使用这个插件可以实现滑动的效果,具体步骤如下:
1、npm 下载
npm install smoothscroll-polyfill --save
2、在main.js中全局引入
import smoothscroll from "smoothscroll-polyfill"
smoothscroll.polyfill();
3、在当前页面使用就引入
import smoothscroll from 'smoothscroll-polyfill';
具体主代码如下:
//注释:这里的 order-lock 是需要跳到的那个标签的类名
this.timer = setTimeout(() => {
smoothscroll.polyfill();
document
.getElementsByClassName('order-lock')[0]
.scrollIntoView({ block: 'start', inline: 'center', behavior: 'smooth' });
}, 3000);