vue数字滚动最后怎么回到0位置
vue数字滚动最后怎么回到0位置?
方法1:
// 可以用来获取top值
// 可以不用加单位,这样写的话就是让滚动到什么位置
document.documentElement.scrollTop = 300
1
2
3
1
2
3
方法2:
//先获取目标位置距离
mounted() {
this.$nextTick(() => {
setTimeout(() => {
let targetbox= document.getElementById('box');
//在data中定义
this.target= targetbox.offsetTop;
} )
} )
}
//再滑动指定距离
document.body.scrollTop = this.target;
1
2
3
4
5
6
7
8
9
10
11
12
1
2
3
4
5
6
7
8
9
10
11
12
方法3:
scrollTo,scrollBy,scroll滚动到某位置
this.$nextTick(() => {
//获取的DOM元素不能为display:none
//一定要加this.$nextTick 这样才可以事实更新
this.$refs.DOM.scrollTo(0,200);
//x 和 y 的 设定位置
} )
//但在this.$nextTick(()里执行滑动,感觉有点麻烦 我还没有使用过
1
2
3
4
5
6
7
1
2
3
4
5
6
7
方法4:
document.getElementById("box").scrollIntoView();
//找到元素 scrollIntoView()方法让当前的元素滚动到浏览器窗口的可视区域内
1
2
1
2
方法5:
scrollBehavior (to, from, savedPosition) {
return { x: 0, y: 0 }
}
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: vue数字滚动最后怎么回到0位置
本文地址: https://pptw.com/jishu/26812.html