A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

[Proposal] Element scroll with ease options

mkay581
2016-09-24

I have created a very very rough, first iteration of a proposal to add a Element.scroll method to the spec that will allow a developer to programmatically scroll an element with easing options.

Please see the explainer at: https://github.com/mkay581/proposal-element-scroll

I would love to get your thoughts!

mkay581
2016-09-25

@tabatkins, you seem to be a go to resource for getting answers in the forum. If not, please feel free to point me to someone else. What are some suggestions on this proposal?

SaschaNaz
2016-09-25

There already is a specification for smooth scroll, which is implemented by Firefox. W3C / MDN

Returning Promise seems great, though.

mkay581
2016-09-25

Thanks @SaschaNaz for the link and the compliments. I did see that and that spec is great, but, unless I’m missing something, it doesn’t seem to account for scrolling individual elements–only the Window, as addressed in my proposal.

Is there any intention to add that API at the Element-level?

SaschaNaz
2016-09-25

The same specification contains extension to the Element interface, which allows scrolling individual elements. http://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface

mkay581
2016-09-25

Ah, yes. I missed that part–sorry.

So it does look pretty solid.

The ScrollBehavior options don’t give much flexibility. I’d like to see more control of the scrolling behavior left up to the developer. And you’re right. It doesn’t seem to have promises in there.

majidvp
2016-09-26

Adding Custom Timing to Existing Scroll APIs

I wonder if the CSSOM has intentionally limited ScrollBehaviour to only “smooth” and “instant” so that user-agent can match the platform conventions in case of “smooth”. There is a hint of that in the spec but @zcorpan is the current editor and can shed some light there.

The proposed change suggests adding a easing function but not a duration. This feels incomplete to me in particular if the user agent decides to scroll with duration = 0 then the easing function becomes irrelevant! This would be a lot more powerful and flexible tool for scroll animations if it did support duration (and even delay) too. At which point, we probably want to have something that is actually part of Web Animation and not tacked onto the CSSOM scroll APIs.

Also I feel that a user-specified timing function makes sense only for a single element scroll operations but it may be inappropriate for ‘scrollIntoView’ case where multiple elements may be scrolled (potentially in parallel).

Returning a Promise

+1 for returning a promise. Although it should be possible to polyfill that using ‘scroll’ event but there are a few corner cases which need to be covered (e.g., reaching to boundaries, scroll being interrupted by use input, etc.) which can make it tricky. This feels like a good extension.

Scroll Animation

I agree that a way to animate scroll positions without jank is missing from the platform. We (in Chrome) certainly are thinking about introducing new primitives for high performance animations which do include scroll position. This does not preclude adding other declarative options where it makes sense.

tabatkins
2016-09-28

Yes, the options are intentionally limited so we can match platform conventions. It turns out that users get really used to how their platform of choice scrolls, and get pretty annoyed when individual apps or pages try to override it. (There’s some scrolling library in the wild that drives me crazy whenever it’s used, because it’s subtly but very noticeably different than how my Chromebook normally scrolls for slow pans.)

There has been explicit pushback from implementors at allowing webpages to customize scrolling behavior for this reason.

mkay581
2016-09-29

Understood, @tabatkins.

However, I don’t think it’s a good idea refuse to implement a feature because we are afraid that developers will use it incorrectly or in a way that we did not intend. I also hate when websites hijack native scroll, but hijacking native scroll or user-initiated scrolls is not my goal here. In fact in the proposal I created, it explains that any user-initiated scrolls will cancel out any JS-initiated scrolls (along with any of their effects). I do think this is the same behavior of the existing Element scroll API also.

One of the bigger use cases is when a user visits urls that are mapped to anchors (sections) on a page. The jarring effect that happens when a user reloads the page or stumbles upon the url is undesirable and, in some cases, confuses the user, making it difficult to get a true sense of where they are on the page. Having these options gives the user a better sense of what section of the page the user is being taken to. This is just one use case, however. I go into a few more on my proposal (i.e. chat windows, etc)

I do think that promises are a good idea (as echoed throughout this thread). Should I open a request against the w3c/csswg-drafts repository for that?

majidvp
2016-09-30

I do think that promises are a good idea (as echoed throughout this thread). Should I open a request against the w3c/csswg-drafts repository for that?

Yes. That is the right place to open an issue.

mkay581
2017-06-25

UPDATE: I’ve created the cssom-view issue requesting that scroll methods return promises. Thanks @majidvp!