1 回答
TA贡献1820条经验 获得超2个赞
因为您每次都添加了事件侦听器。
解决方案:
function handleChange(checkbox) {
const animation = document.getElementById("overlay");
if(checkbox.checked === true){
if (window.innerWidth < 846) {
animation.style.display="block";
animation.style.animationName="appear";
animation.style.animationPlayState = "running";
document.getElementById('overlay2').style.display="none";
disableScroll();
}
return false;
} else {
animation.style.animationName="disappear";
animation.style.animationPlayState="running";
const singleEvent = () => {
animation.style.display="none";
document.getElementById("overlay2").style.display="block";
animation.removeEventListener('animationend', singleEvent)
};
animation.addEventListener('animationend', singleEvent);
enableScroll();
return false;
}
}
添加回答
举报