Note that there are some explanatory texts on larger screens.

plurals
  1. POList Does Not Reappear on Window Resize
    primarykey
    data
    text
    <p>I have a dropdown manu that I have made responsive using CSS and jQuery. If the window is shrunk the mobile nav appears just fine, but if you expand and close the menu, and then resize your window larger, the desktop nav does not reappear due to the inline display: none added by the slideToggle. I can't figure out, for the life of me, how to get the menu to reappear when the window size is increased again.</p> <p>HTML</p> <pre><code>&lt;div class="nav"&gt; &lt;div class="mobile-nav"&gt;Navigation&lt;/div&gt; &lt;ul class="primary"&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="has-drop"&gt;Link w/ Children &lt;span&gt;&lt;/span&gt;&lt;/a&gt; &lt;ul class="drop"&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a class="has-drop" href="#link"&gt;Link w/ Children &lt;span&gt;&lt;/span&gt;&lt;/a&gt; &lt;ul class="drop"&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#link"&gt;Link&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>CSS</p> <pre><code>.clear{clear:both} .nav{display:block;width:100%;background:#222} .mobile-nav{visibility:hidden;padding:0;height:0;background:#222} ul.primary{background:#222;list-style:none;height:45px;min-width:350px;position:relative;margin:10px 0 0 0;padding:0;float:right;display:block} ul.primary li{float:left;display:inline;font-weight:bold;font-size:13px;max-width:100%} ul.primary li a,ul.drop li a{display:block;padding:10px;color:white;text-decoration:none} ul.drop li a{padding:5px} ul.primary li a:hover,ul.drop li a:hover{background:#444} ul.primary li,ul.drop li{font-family:"Helvetica Neue","Helvetica",Helvetica,Arial,sans-serif} ul.primary li.active&gt;a{background:#444} a.has-drop{cursor:pointer} a.has-drop span{margin:-8px 0 0 5px;width:10px;height:5px;float:right;background:url("drop-caret.png") no-repeat center right} li.active&gt;a.has-drop span{margin:-8px 0 0 5px;width:10px;height:5px;float:right;background:url("drop-caret-up.png") no-repeat center right} ul.drop{display:none;z-index:999;position:relative;margin:0;padding:0;min-width:100%;width:auto;list-style:none;background:#242424;border:0} ul.drop li{float:none;font-weight:normal} @media only screen and (max-width:767px){ nav{display:block;width:100%;border:0 solid white;padding:10px 0} .mobile-nav{visibility:visible;height:auto;margin:0 5px;padding:10px 0;font-weight:bold;color:white;cursor:pointer;background:url("mobile-nav.png") no-repeat center right} ul.primary{float:none;display:none;height:auto;margin:0;padding:0} ul.primary li{display:block;float:none;border-bottom:1px solid #444} ul.primary li:last-child{border-bottom:0} ul.drop li,ul.primary li.active{border-bottom:0} ul.drop li a{text-indent:15px;font-size:12px;font-style:italic} a.has-drop span{margin:5px 0 0 5px;width:10px;height:5px;float:right;background:url("drop-caret.png") no-repeat center right} li.active&gt;a.has-drop span{margin:5px 0 0 5px;width:10px;height:5px;float:right;background:url("drop-caret-up.png") no-repeat center right}}​ </code></pre> <p>jQuery</p> <pre><code>var $j = jQuery.noConflict(); $j(document).ready(function () { $j('ul.primary li').click(function () { var a = this; if ($j('ul', this).is(':visible')) { $j('ul', this).slideUp(function () { $j(a).removeClass('active') }) } else { $j('ul.drop').slideUp(); $j('ul.primary li').removeClass('active'); $j('ul', this).slideDown(); $j(a).addClass('active') } }); $j('body').click(function (a) { if (!$j(a.target).is('a')) { $j('ul.drop').slideUp(); $j('ul.primary li').removeClass('active') } }); $j(function () { $j('.mobile-nav').click(function (e) { $j('.primary').slideToggle(150, "swing"); e.stopPropagation() }); $j(window).resize(function() { $j('ul.drop').slideUp(); $j('ul.primary li').removeClass('active') }); }) }); </code></pre> <p>Here is the full markup and jQuery: <a href="http://jsfiddle.net/mhXkM/" rel="nofollow">http://jsfiddle.net/mhXkM/</a></p> <p>Any help would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload