Javascript - 滚动方向检测addEventListener'滚动'

时间:2016-12-31 13:58:19

标签: javascript jquery mouseevent mouselistener

我有固定标题,使用鼠标滚动 如何更改此代码仅适用于向上滚动

function init() {
                    window.addEventListener( 'scroll', function( event ) {
                        if( !didScroll ) {
                            didScroll = true;
                            setTimeout( scrollPage, 250 ); //Scroll Page
                        }
                    }, false );
                }

//滚动功能

                function scrollPage() {
                    var sy = scrollY();                      

                    if ( sy >= changeHeaderOn ) {
                        if(!$('.template-content').hasClass('fixed-active') && (!$('.header-wrapper').hasClass('slider-overlap') || $('body').hasClass('breadcrumbs-type-9') || $('body').hasClass('breadcrumbs-type-default')) )
                        etTheme.headerHeight('set');
                        classie.add( wrapper, 'fixed-active' );
                        setTimeout( function() {
                            classie.add( wrapper, 'fixed-active-animate' );
                        },250);
                    }
                    else {
                        classie.remove( wrapper, 'fixed-active' );
                        classie.remove( wrapper, 'fixed-active-animate' );
                        etTheme.headerHeight('unset');
                    }
                    didScroll = false;
                }

//滚动位置

                function scrollY() {
                    return window.pageYOffset || docElem.scrollTop;
                }

//调用函数

                init();

1 个答案:

答案 0 :(得分:0)

function scrollPage() {
                    var sy = scrollY();
                    if ( sy >= changeHeaderOn && LastscrollY > sy) {
                        if(!$('.template-content').hasClass('fixed-active') && (!$('.header-wrapper').hasClass('slider-overlap') || $('body').hasClass('breadcrumbs-type-9') || $('body').hasClass('breadcrumbs-type-default')) )
                        etTheme.headerHeight('set');
                        classie.add( wrapper, 'fixed-active' );
                        setTimeout( function() {
                            classie.add( wrapper, 'fixed-active-animate' );
                        },250); //150
                    }
                    else {
                        classie.remove( wrapper, 'fixed-active' );
                        classie.remove( wrapper, 'fixed-active-animate' );
                        etTheme.headerHeight('unset');
                    }
                    didScroll = false;
                    LastscrollY = sy;
                }