8000 [cssom-view] Consider making scroll methods return promises · Issue #1562 · w3c/csswg-drafts · GitHub 8000
[go: up one dir, main page]

Skip to content

[cssom-view] Consider making scroll methods return promises #1562

@markcellus

Description

@markcellus

Smooth scrolling has been introduced into the spec where the scroll happens over a period of time, which is great. However, I think it would be even more useful if scroll method returned a promise so the developer could wait until the scroll finishes before moving on to next set of tasks for things like triggerin 6D43 g analytics data after scrolling, unloading resources when they've been scrolled out of view, parallax scrolling, etc.

Obviously scroll()ing an element that has scroll-behavior option set to auto makes scroll instant and is therefore not inherently asynchronous. But I think, to keep the API consistent, the scroll method should return a promise every time it is used.

So if you had the following HTML...

<div id="scroll-container" style="scroll-behavior: smooth;">
   <!-- other content here --> 
</div>

you can do this...

let element = document.getElementById('scroll-container');
element.scroll(0, 400).then(() => {
   // ...scroll has finished
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0