scrollToTop 滚动到顶端
作者:程序员11 时间:2022-12-14 人气:351 QQ交流群\邮箱:1003265987@qq.com
scrollToTop 滚动到顶端
要展示的内容
scrollToTop(){
clearInterval(this.timer);
//加入定时器让他又快到慢滚动到顶部
this.timer = setInterval(()=>{
//获取当前scrollTop的高度位置(兼容ie和chrom浏览器)
let oTop = document.documentElement.scrollTop || document.body.scrollTop;
//设置速度由快到慢
let isPeed = Math.floor(-oTop / 7);
document.documentElement.scrollTop = document.body.scrollTop = oTop + isPeed;
this.oScroll = true;
if(oTop === 0){
clearInterval(this.timer);
}
},30);
/* const element = document.getElementById("body");
element.scrollIntoView({
behavior: 'smooth', //平滑滚动,爽,其他还有 instant
block: 'start' //元素到页面顶部,其他还有 end, center
})*/
},
温馨提示:
欢迎阅读本文章,觉得有用就多来支持一下,没有能帮到您,还有很多文章,希望有一天能帮到您。
- 上一篇:如何确定HTML元素是否在屏幕外?
- 下一篇:jQuery的在线涂鸦插件wPaint
HTML5-热门文章
活跃用户












