简体   繁体   中英

Hotdog menu closes when I scroll on mobile. Need it to stay open

this is the javascript. I think it has to do with the window resizing. the menu collapses when I try and scroll to more items in the menu on mobile. Any help would be greatly appreciated.

jQuery(document).ready(function($){

    $(window).scroll(function(){
        var windowWidth = $(window).width();
        if(windowWidth > 768 ){
            if($(window).scrollTop() > 65){
                $('.sm-logo').slideDown();
            }else{
                $('.sm-logo').slideUp();
            }   
        }else{
            $('.sm-logo').slideUp();
        }
    });

    $(window).on('resize',function(){

        var windowWidth = $(window).width();
        console.log(windowWidth);
        if(windowWidth < 768 ){

            $('nav ul').slideUp();
            $('.hamburger').removeClass('open').addClass('closed');
        }else{

            $('.hamburger').removeClass('closed').addClass('open');
            $('nav ul').slideDown();


        }
    });
    $(document).on('click','.hamburger', function(){
        $(this).toggleClass('open closed');
        $('nav ul').slideToggle();
    });


});

It's hard to tell exactly what's going on without a working example, plus I'm on my mobile device, but inside your on resize function, it says to slide up the nav if the screen is less than 768 px.

That slide up method should not be there.

$('nav ul').slideUp();

Perhaps you actually have the slide up and slide down methods reversed, try swapping them.

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