A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/w3c/csswg-drafts/issues/1562 below:

[cssom-view] Consider making scroll methods return promises · Issue #1562 · w3c/csswg-drafts · GitHub

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 triggering 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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4