-
Notifications
You must be signed in to change notification settings - Fork 747
Open
Description
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
});
majido, jraoult, dartess, jonjohnjohnson, saschanaz and 17 more