vue设置页面滚动高度_vue中获取滚动高度或指定滚动到某位置
1.点击某个标签,滚动到某个具体位置switchHeight(num) {this.selectNum = num;if (num == 0) {document.getElementById("identifer_one").scrollIntoView();} else {document.getElementById("hotel_two").scrollIntoView();}},2.获取
1.点击某个标签,滚动到某个具体位置
switchHeight(num) {
this.selectNum = num;
if (num == 0) {
document.getElementById("identifer_one").scrollIntoView();
} else {
document.getElementById("hotel_two").scrollIntoView();
}
},
2.获取滚动高度,
首先要先写监听事件:
mounted() {
window.addEventListener("scroll", this.handleScroll, true); //监听滚动事件
},
处理监听事件:e.target.scrollTop是目标对象的滚动高度
handleScroll(e) {
let serviceTop = 44;
let hotelTop = 344;
if (e.target.scrollTop > 44 && e.target.scrollTop < 344) {
this.selectNum = 0;
}
if (e.target.scrollTop > 344) {
this.selectNum = 1;
}
}
},
更多推荐
所有评论(0)