How long is the delay for CSS scroll snap?

我是研究僧i 提交于 2021-02-07 19:11:51

问题


After you scrolled in a container which has some sort of CSS scroll-snapping active, how long is the delay since user-scrolling ended that the browser starts scrolling to the snapping position?

Motivation

I wrote an answer to question CSS Scroll Snap with Animation Effect where I simulate a scrollend event by debouncing the scroll event callback by 250 ms. This seems to be close enough to the real value in Chrome browser. But it would be nice to get some first-class values. There might even be an API somewhere so that I can get the correct value by JS.


回答1:


CSS Scroll Snap Module Level 1:

The CSS Scroll Snap Module intentionally does not specify nor mandate any precise animations or physics used to enforce snap positions; this is left up to the user agent.

I strongly assume that most browsers that support scroll snapping (e.g. Firefox) use the same functionality that they already use for scroll-behavior: smooth;.

CSSWG - Smooth Scrolling:

The scrolling box is scrolled in a smooth fashion using a user-agent-defined timing function over a user-agent-defined period of time. User agents should follow platform conventions, if any.

This means that there might be differences not only between browsers, their specific versions, but also depending on the operating system they are running on. Also note that browsers might or might not change animations based on the user settings (e.g. because of accessibility concerns).

I do not think that there is an API to get the exact delays and/or smoothing functions.



来源:https://stackoverflow.com/questions/56362168/how-long-is-the-delay-for-css-scroll-snap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!