const options = {
offset: -50
};
export default {
name: 'BarMenu',
data() {
return {
scrollingDirection: '',
}
},
computed: {
cssClasses() {
return {
hidden: this.scrollingDirection === 'down'
}
}
},
mounted() {
this.onScroll();
},
methods: {
scrollToIngredients() {
return this.$scrollTo(document.getElementById('ingredients-inside-content'), 600, options);
},
scrollToRecipes() {
return this.$scrollTo(document.getElementById('similar-recipes'), 600, options);
},
scrollToComments() {
return this.$scrollTo(document.getElementById('comments'), 600, options);
},
onScroll() {
let lastScrollTop = 0;
const handler = () => {
let st = window.pageYOffset || document.documentElement.scrollTop;
if (st > lastScrollTop) {
this.scrollingDirection = 'down';
} else {
this.scrollingDirection = 'up';
}
lastScrollTop = st <= 0 ? 0 : st;
};
window.removeEventListener("scroll", handler, false);
window.addEventListener("scroll", handler, false);
}
},
}
这条线不工作,为什么?window.removeEventListener("scroll", handler, false); 我尝试了所有方法:箭头函数、函数声明等。但是那个事件监听器根本没有删除。
慕侠2389804
千万里不及你
相关分类