扫码关注官方订阅号
<script> window.onload=function(){ var oDelta=document.getElementById('Delta'); var op=oDelta.getElementsByTagName("p"); var firstp=op[0]; var pisscrolling=false; var movingValue=0; var requestAnimationFrameId; var currentpFrame=0; var pFrameLength=op.length; var wheelTimerID=null; oDelta.addEventListener("wheel",wheelListener,false); //控制wheel时间间隔,如果一定时间内没有没有变化 var getScrollDownFlag=(function(){ var scrollDownFlag=false; return function(deltaYIn){ if(deltaYIn<0){ scrollDownFlag=false; }else if(deltaYIn>0){ scrollDownFlag=true; } return scrollDownFlag; } }()); function wheelListener(event){ //使用触控板的话,短时间内会触发大量的wheel事件 clearTimeout(wheelTimerID); var scrollDownFlag=getScrollDownFlag(event.deltaY); wheelTimerID=setTimeout(function(){ if(pisscrolling){ event.preventDefault(); return; } doWhenWheelEvent(scrollDownFlag); },100); } function doWhenWheelEvent(scrollDownFlag){ console.log(scrollDownFlag,pisscrolling); if(!pisscrolling&&(currentpFrame>=0&¤tpFrame<=pFrameLength-1)){ //console.log(scrollDownFlag,currentpFrame); if((scrollDownFlag&¤tpFrame<pFrameLength-1) ||(!scrollDownFlag&¤tpFrame>0&¤tpFrame<=pFrameLength-1)){ pisscrolling=true; oDelta.removeEventListener("wheel",wheelListener,false); doScorllAnimation(scrollDownFlag); } } } function doScorllAnimation(scrollDownFlag){ if(movingValue+10<=100){ movingValue=movingValue+10; firstp.style.marginTop=((currentpFrame)*100*-1+(movingValue)*(scrollDownFlag?-1:1))+"vh"; requestAnimationFrameId=requestAnimationFrame(doScorllAnimation.bind(null,scrollDownFlag)); }else{ pisscrolling=false; movingValue=0; oDelta.addEventListener("wheel",wheelListener,false); currentpFrame=currentpFrame+(scrollDownFlag?1:-1); } } }; </script>
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部