javascript - 关于fullpage动画的问题,请前辈们赐教
巴扎黑
巴扎黑 2017-04-11 10:39:49
[JavaScript讨论组]
巴扎黑
巴扎黑

全部回复(1)
阿神
<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&&currentpFrame<=pFrameLength-1)){
                    //console.log(scrollDownFlag,currentpFrame);
                    if((scrollDownFlag&&currentpFrame<pFrameLength-1)
                            ||(!scrollDownFlag&&currentpFrame>0&&currentpFrame<=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中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号