This commit is contained in:
clay
2022-01-22 00:57:57 +08:00
parent 2c4b597942
commit 72fbaed559
16 changed files with 267 additions and 217 deletions

View File

@@ -51,6 +51,18 @@ export default {
document.onmousewheel = this.scrollFun;
}
},
beforeDestroy() { //及时释放
// 浏览器兼容
if ((navigator.userAgent.toLowerCase().indexOf("firefox") != -1)) {
document.removeEventListener("DOMMouseScroll", this.scrollFun, false);
} else if (document.addEventListener) {
document.removeEventListener("mousewheel", this.scrollFun, false);
} else if (document.attachEvent) {
document.removeEventListener("onmousewheel", this.scrollFun);
} else {
document.onmousewheel = this.scrollFun;
}
},
methods: {
scrollFun(event) {
//console.log(this.main,this.page2.offsetTop,this.screenHeight)
@@ -60,18 +72,19 @@ export default {
let delta = event.detail || (-event.wheelDelta);
console.log(delta)
// 如果当前滚动开始时间和上次滚动结束时间的差值小于1.5s,则不执行翻页动作,这样做是为了实现类似节流的效果
if ((this.startTime - this.endTime) > 1000) {
if (delta > 0 && window.pageYOffset < 937) {
if ((this.startTime - this.endTime) > 1) {
if (delta > 0 && window.pageYOffset < window.innerHeight) {
// // 向下滚动
// this.index = 2;
// this.toPage(this.index);
window.scrollTo({top: 937, behavior: 'smooth',})
} else if (delta < 0 && parseInt(this.main.offsetTop) == 0) {
window.scrollTo({top: window.innerHeight+20, behavior: 'smooth',})
} else if (delta < 0 && window.pageYOffset <= window.innerHeight+200) {
// // 向上滚动
//
//
//
//
window.scrollTo({top: 0, behavior: 'smooth',})
// this.index = 1;
// this.toPage(this.index);
}