0π
β
I find the reason!It because I set a EventListener and I donβt remove it.Here is my revised code:
function clear() {
isClick = true
clearInterval(scrollToAnimation)
scrollToAnimation = null
per_distance = null
top_distance = null
per_time = 0
}
function monitorWheel() {
window.removeEventListener('scroll', monitorScroll)
if (docEl.scrollTop == location) {
clear()
window.removeEventListener('wheel', monitorWheel)
window.removeEventListener('scroll', monitorScroll)
} else {
setTimeout(() => {
clear()
window.removeEventListener('wheel', monitorWheel)
window.removeEventListener('scroll', monitorScroll)
}, per_time * 20)
}
}
function monitorScroll() {
if (docEl.scrollTop == location) {
clear()
window.removeEventListener('wheel', monitorWheel)
window.removeEventListener('scroll', monitorScroll)
} else {
setTimeout(() => {
clear()
window.removeEventListener('wheel', monitorWheel)
window.removeEventListener('scroll', monitorScroll)
}, per_time * 20)
}
}
window.addEventListener('wheel', monitorWheel)
window.addEventListener('scroll', monitorScroll)
After this modify,when the scroll animate is over,the EventListener will be remove,then question is solved!
Source:stackexchange.com