【发布时间】:2019-04-10 02:31:55
【问题描述】:
我目前正在使用framework7,我遇到了这个问题,一旦用户通过滚动特定元素,我需要让一个按钮浮动。
但由于某种原因,我无法使滚动事件起作用。甚至使用了原生事件监听器,但仍然没有运气。
这是我的代码。在我的组件中:
export default {
methods: {
handleScroll(event) {
alert('should work')
}
},
created() {
window.addEventListener('scroll', this.handleScroll);
},
destroyed() {
window.removeEventListener('scroll', this.handleScroll);
},
mounted() {
window.addEventListener('scroll', this.handleScroll)
this.handleScroll;
var element = document.querySelector(".similar-adventures");
var top = element.offsetTop;
window.scrollTo(0, top);
}
}
这是我的原生事件监听器代码:
window.addEventListener(‘scroll’, function(e){
// Get the new Value
newValue = window.pageYOffset;
//Subtract the two and conclude
if(oldValue - newValue < 0){
console.log(“Up”);
} else if(oldValue - newValue > 0){
console.log(“Down”);
}
// Update the old value
oldValue = newValue;
});
【问题讨论】:
标签: javascript vue.js html-framework-7