Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can simplify it this way:</p> <p>HTML :</p> <ul> <li>Give a common class <code>panel</code> to all panels</li> <li>Give a common class to menu links <code>menuLink</code></li> <li>For the menu links provide href as the id of its target panel.</li> </ul> <p>Source:</p> <pre><code>&lt;div class="wrap"&gt; &lt;div id="panel1" class="panel"&gt; &lt;h1&gt;PANEL1&lt;/h1&gt; &lt;/div&gt; &lt;div id="panel2" class="panel"&gt; &lt;h1&gt;PANEL2&lt;/h1&gt; &lt;/div&gt; &lt;div id="panel3" class="panel"&gt; &lt;h1&gt;PANEL3&lt;/h1&gt; &lt;/div&gt; &lt;div id="panel4" class="panel"&gt; &lt;h1&gt;PANEL4&lt;/h1&gt; &lt;/div&gt; &lt;div id="panel5" class="panel"&gt; &lt;h1&gt;PANEL5&lt;/h1&gt; &lt;/div&gt; &lt;/div&gt; &lt;!--end wrap--&gt; &lt;ul class="nav"&gt; &lt;li&gt;&lt;a class="menuLink" href="#panel1"&gt;link1&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a class="menuLink" href="#panel2"&gt;link2&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a class="menuLink" href="#panel3"&gt;link3&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a class="menuLink" href="#panel4"&gt;link4&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a class="menuLink" href="#panel5"&gt;link5&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>JS:</p> <pre><code>$(document).ready(function () { var timeout, $panel = $('.panel'); //Just bind event handler once $(".menuLink").click(function (event) { event.preventDefault(); //Clear any timeout if clicked withing 2 sec after hovering out of wrap clearTimeout(timeout); //get the target element reading the href and set its css var $target = $(this.getAttribute('href')).css({ height: 150, top: 20 }); //Do for all panels but the target. $panel.not($target).css({ height: 0, top: -500 }); }); $(".wrap").mouseleave(function () { timeout = setTimeout(function () { $panel.css({ height: 0, top: -500 }) }, 2000); }); }); </code></pre> <p><strong><a href="http://jsfiddle.net/NYgKb/" rel="nofollow">Demo</a></strong></p>
 

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