Browser compatibility and Scroll Snap - CSS: Cascading Style Sheets 编辑

Firefox initially implemented an early version of the Scroll Snap Specification, called Scroll Snap Points. In Firefox 68 the new version of the specification will be shipped and these old properties removed.

In this article, we consider questions that might arise related to compatibility across browsers and versions of browsers when adding support for scroll-snap to your web site or app.

What should I do if I used the old Firefox implementation?

If you have only used the old Firefox implementation of the specification, with the properties that are detailed in Scroll Snap Points, you should update your code to use the new specification. This will ensure your scroll snapping works in all browsers which implement the specification, including Firefox. If you do not do this your scroll snapping will no longer work in Firefox 68 and up.

The main things to note are as follows:

Can I use the old implementation as a fallback?

If you have already used the old implementation as a fallback, or feel you want to support users of old Firefox (or -webkit prefixed Safari), then you can continue to use the old specification as outlined in the example below.

In this initial example we have used the old specification alongside the current specification in order to make scroll snapping work in all browsers which support some form of scroll snapping.

The example adds the scroll-snap-points-y and scroll-snap-destination properties, which are deprecated, to make scroll snapping work in Firefox. We also added the scroll-snap-type property twice, once with the y axis value needed for browsers that support the new spec, and once for Firefox pre-68, which supports the property but without the y value.

Do I need to use both specs?

Scroll snapping is one of those nice parts of CSS in which the fallback is that you don't get the enhanced functionality, but everything still works. I would suggest at this point you should implement the new specification only, unless you have data to show a large number of users who would benefit from a fallback version.

If you want to test using Feature Queries for support of the new spec then we'd suggest testing for scroll-snap-align as this property did not exist in the old implementation. However, these properties shouldn't cause any problems to non-supporting browsers due to the way that browsers ignore CSS that they do not understand.

Why are there two versions of scroll snap?

Finally, you might wonder why we ended up in a scenario where two versions exist at all. This is the reality of developing new CSS — it can't be developed in a vacuum away from browser implementations. At some point browsers need to implement a spec to show that it works, and to discover any problems that only become apparent when the spec is in use alongside other properties in the real world. In such cases we can end up with implementations of older versions available alongside newer versions as browsers are in the process of updating.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:73 次

字数:4834

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文