首页 > 解决方案 > 如何在 Edge 中设置滚动行为?

问题描述

我想使用具有平滑行为的 scrollLeft 方法,但 Edge 不支持它。我该怎么做?类似 menu.scrollBy({ left: 100, behavior: 'smooth' });但在 Edge 中。

标签: javascriptmicrosoft-edge

解决方案


我建议你检查Smooth scroll behavior polyfill。它在Edge浏览器中受支持。

滚动行为规范已作为 Window 界面的扩展引入,以允许开发人员选择加入原生平滑滚动。检查GitHub 上的存储库或将 polyfill 作为npm模块下载。

例子:

window.scroll({ top: 2500, left: 0, behavior: 'smooth' });

参考:

平滑滚动行为 polyfill


推荐阅读