Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>May I suggest using this javascript plugin? <br /> <a href="http://www.scriptiny.com/2008/05/sliding-javascript-menu-highlight-1kb/" rel="nofollow">http://www.scriptiny.com/2008/05/sliding-javascript-menu-highlight-1kb/</a></p> <p>It has the functionality you are trying to recreate. Why try to recreate the wheel?</p> <p><strong>Edit 1</strong></p> <p>Anyway, if you did want to do this with your code, here is a reworking. </p> <p><strong>HTML</strong></p> <pre><code>&lt;div id="pmenu"&gt; &lt;ul id="bmenul"&gt; &lt;li&gt;&lt;a class="brand" id="fxmenu1_" href="/"&gt;LOGO&lt;/a&gt; &lt;/li&gt; &lt;li class="active"&gt;&lt;a id="fxmenu_2" href="/team" title="team"&gt;The team&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a id="fxmenu_3" href="/services" title="Servicios"&gt;Services&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a id="fxmenu_4" href="/projects" title="Proyectos"&gt;Projects&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a id="fxmenu_5" href="/contact" title="Contacto"&gt;Contact&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;div id="bar"&gt; &lt;div id="img"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>Javascript</strong> </p> <pre><code>$(document).ready(function() { var activeIndex = $('#bmenul &gt; li.active').index(); $('#img').css({ 'marginLeft': (180 * activeIndex) + 'px' }).show(); $('#bmenul &gt; li').not('.active').hover(function() { var index = $(this).index(); $('#img').stop().animate({ 'marginLeft': (180 * index) + 'px' }, 400); }, function() { $('#img').stop().animate({ 'marginLeft': (180 * activeIndex) + 'px' }, 400); }); });​ </code></pre> <p><strong>CSS</strong></p> <pre class="lang-css prettyprint-override"><code>... #img { max-height: 180px; width: 180px; border-bottom: 2px solid #000000; display: none; } </code></pre> <p><strong><a href="http://jsfiddle.net/rzJMv/7/" rel="nofollow">Demo</a></strong></p>
    singulars
    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