简体   繁体   中英

Javascript - scroll direction Detect in addEventListener 'scroll'

I have Fixed Header ,That Work With Mouse Scroll How Change This code That Work only With Scroll UP

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

//Scroll Function

                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;
                }

//Scroll Position

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

//Call Function

                init();
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;
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM