当前位置: 首页 > 工具软件 > smoothscroll > 使用案例 >

在Vue项目中使用smoothscroll-polyfill(页面平滑滚动)插件

微生俊名
2023-12-01

smoothscroll-polyfill 是什么?

           它是一款纯JS页面的平滑滚动插件。该插件的特点是页面滚动的行为被作为window对象的扩展,用户可以通过window对象直接调用平滑滚动的方法。

 官方介绍及Demo

GitHub源码地址

smoothscroll-polyfill  什么使用?

            1、安装插件

npm install smoothscroll-polyfill --save

           2、在main.js中全局引入该插件


import smoothscroll from 'smoothscroll-polyfill';
 
smoothscroll.polyfill();

           3、使用该插件

 window.scroll({
       top: scrollTop - 20,
       left: 0,
       behavior: "smooth", //滚动条平滑滚动
 });

 

 类似资料: