2017-01-05 79 views
0

如何在使用滾動時關閉推式畫布菜單?或點擊它。滾動時關閉推式菜單

以下是HTML和Jquery。提前致謝!

$(document).ready(function() { 
 
    $menuLeft = $('.pushmenu-left'); 
 
    $nav_list = $('#nav_list'); 
 

 
    $nav_list.click(function() { 
 
    $(this).toggleClass('active'); 
 
    $('.pushmenu-push').toggleClass('pushmenu-push-toright'); 
 
    $menuLeft.toggleClass('pushmenu-open'); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<nav class="pushmenu pushmenu-left"> 
 
    <div class="menu-primary-container"> 
 

 
    <ul id="menu-primary" class="menu"> 
 
     <li><a href="http://10.0.0.127:8888/page16-sass/">Home</a></li> 
 
     <li><a href="http://10.0.0.127:8888/page16-sass/creative/">Creative</a></li> 
 
     <li><a href="http://10.0.0.127:8888/page16-sass/online/">Online</a></li> 
 
     <li><a href="http://10.0.0.127:8888/page16-sass/print/">Print</a></li> 
 
     <li><a href="http://10.0.0.127:8888/page16-sass/the-studio/">The Studio</a></li> 
 
     <li><a href="http://10.0.0.127:8888/page16-sass/work/">Our Work</a></li> 
 
     <li><a href="http://10.0.0.127:8888/page16-sass/snippets/">Snippets</a></li> 
 
     <li><a href="http://10.0.0.127:8888/page16-sass/blog/">Blog</a></li> 
 
     <li><a href="http://10.0.0.127:8888/page16-sass/contact/">Get in touch</a></li> 
 
    </ul> 
 
    </div> \t \t 
 

 
    <div class="mobile-phone">01268 271 858</div> 
 
</nav>

+0

請問您能否分享所需的CSS。在這裏很容易重現這個問題。 – vijayP

回答

0

切換上滾動你的pushmenu類。

window.addEventListener('scroll', function(e) { 
    $('.pushmenu-push').removeClass('pushmenu-push-toright'); 
    $menuLeft.removeClass('pushmenu-open'); 
}); 
你可能要添加定時器,以防止從菜單滾動,如果用戶選擇一個菜單項之前意外滾動(可能發生在觸摸設備上)