Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Instead of changing <code>id</code> attributes (which you really shouldn't do in the first place) you can change CSS classes and use jQuery UI's <code>switchClass()</code> method to animate the rotation.</p> <p>You would also have to do a bit of <code>clone()</code>ing to make it look like the edge <code>navblock</code>s have rotated around to the other side of the widget and some <code>queue()</code>/<code>dequeue()</code>ing to handle multiple clicks.</p> <h2>Working Demo:</h2> <p><a href="http://jsbin.com/ovemu" rel="nofollow noreferrer">http://jsbin.com/ovemu</a> (editable via <a href="http://jsbin.com/ovemu/edit" rel="nofollow noreferrer">http://jsbin.com/ovemu/edit</a>)</p> <h2>Full Source:</h2> <h3>JavaScript</h3> <pre><code>function rotateNav(direction) { if (direction === 'left') { var change = 1; $('.navblock5').clone() .removeClass('navblock5') .addClass('navblock0') .appendTo('#nav'); } else { var change = -1; $('.navblock1').clone() .removeClass('navblock1') .addClass('navblock6') .appendTo('#nav'); } $('div.navblock').each(function() { var oldClassName = this.className.split(' ')[1], oldPos = parseInt(oldClassName.substr(8)), newPos = oldPos + change; $(this).switchClass( oldClassName, 'navblock'+newPos, 'fast', function () { var animated = $('.navblock:animated').length; if (newPos === 6 || newPos === 0) { $(this).remove(); } if (animated === 1) { $('#nav').dequeue(); } } ); }); } $(document).ready(function(){ $("#leftnav").click(function() { $('#nav').queue(function(){rotateNav('right');}); }); $("#rightnav").click(function() { $('#nav').queue(function(){rotateNav('left');}); }); }); </code></pre> <h3>CSS</h3> <pre> #nav { width: 580px; height: 120px; position: relative; left: 150px; overflow: hidden; } .navblock { height: 100px; width: 100px; position: absolute; top: 10px; z-index: 50; background-color: grey; } .navblock0 { left: -110px; } .navblock1 { left: 10px; } .navblock2 { left: 120px; } .navblock3 { left: 230px; width: 120px; height: 120px; top: 0;} .navblock4 { left: 360px; } .navblock5 { left: 470px; } .navblock6 { left: 590px; } #leftnav, #rightnav { position: absolute; z-index: 100; height: 120px; width: 228px; } #leftnav { left: 0; } #rightnav { right: 0; } /*Uncomment the following to help debug or see the inner workings */ /* #nav { border: 1px solid green; overflow: visible; } #leftnav, #rightnav { border: 1px solid blue; } */ </pre> <h3>HTML</h3> <pre><code>&lt;div id="nav"&gt; &lt;div id="leftnav"&gt;&lt;/div&gt; &lt;div id="rightnav"&gt;&lt;/div&gt; &lt;div class="navblock navblock1"&gt;one&lt;/div&gt; &lt;div class="navblock navblock2"&gt;two&lt;/div&gt; &lt;div class="navblock navblock3"&gt;three&lt;/div&gt; &lt;div class="navblock navblock4"&gt;four&lt;/div&gt; &lt;div class="navblock navblock5"&gt;five&lt;/div&gt; </code></pre>
 

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