简体   繁体   English

jQuery .slideToggle,显示:无

[英]jQuery .slideToggle, display:none

I have a logic problem. 我有一个逻辑问题。 I have a CSS drop down menu, which when the browser, or mobile phone, width is less that 690pixles becomes a menu that is only displayed on a toggle. 我有一个CSS下拉菜单,当浏览器或移动电话的宽度小于690pixles时,它将变为仅在切换开关上显示的菜单。 Ie the user needs to press a button to display the menu. 即,用户需要按下按钮以显示菜单。 However, a logic problem is that if you resize the broswer, toggle the menu to open, then close it again and resize the browser to full width the normal menu disappears because slideToggle adds the display:none; 但是,逻辑上的问题是,如果您调整浏览器的大小,请切换菜单以将其打开,然后再次将其关闭,然后将浏览器的大小重新调整为全宽,则普通菜单会消失,因为slideToggle添加了display:none;。 style to the div element - which then causes a layout problem and is not very user friendly. div元素的样式-然后会导致布局问题,并且不是非常用户友好。 Any ideas how to fix? 任何想法如何解决?

HTML: HTML:

<div id="primary-menu" class="drop-down">
    <div class="menu-toggle">menu-toggle</div>
    <ul id="responsive" class="menu">
        <li class="menu-item"><a href="#">Link 1</a></li>      
        <li class="menu-item"><a href="#">Link 2</a>
            <ul class="child-menu">
                <li class="menu-item"><a href="#">Link A</a></li>
                <li class="menu-item"><a href="#">Link B</a></li>
                <li class="menu-item"><a href="#">Link C</a></li>
            </ul>
        </li>
        <li class="menu-item"><a href="#">Link 3</a></li>
    </ul>
</div>

jQuery: jQuery的:

$(".menu-toggle").click(function(){
    $("#responsive").slideToggle( "slow", function() {});
});

You could show it and hide it on window resize, so that you make sure the menu is always visible in big screens and not visible in small screens. 您可以显示它并在调整窗口大小时将其隐藏,以确保菜单始终在大屏幕中可见,而在小屏幕中不可见。

$( window ).resize(function() {
    if($( window ).width() >= 690) {
        $("#responsive").show();
    }
    else {
        $("#responsive").hide();
   }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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