Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is the slide effect being used because the <code>&lt;a&gt;</code> slides in from the left and gets a second <code>.hover()</code> event. I use the fact that the element gains <code>position:relative</code> from jQueryUI when it is animating to determine whether to add the effect or not.</p> <p><a href="http://jsfiddle.net/Wu8QJ/" rel="nofollow"><strong>Demo</strong></a></p> <p>Adding the CSS</p> <pre><code>#menu a:hover { background-color:white; color:black; }​ </code></pre> <p>and simply using <a href="http://api.jquery.com/mouseenter/" rel="nofollow"><code>.mouseenter()</code></a></p> <pre><code>$('#menu a').mouseenter(function() { var $this = $(this); if ($this.css('position') === 'relative') return; $(this).effect('slide'); // EFFECT });​ </code></pre> <p>seems to solve it for me.</p> <p><strong>Edit:</strong> So thanks to Matthew in the comments for pointing out that when hovering on the far right, the event still fires multiple times. So here is an updated answer. It uses the newer jQuery <a href="http://api.jquery.com/on/" rel="nofollow"><code>.on()</code></a> syntax but you could still use the older methods to achieve the same result. It now uses two events, one on the anchors to add the <em>hover</em> style and effect but <strong>only</strong> if when entering the anchor, the element does not already have the class. I also remove the hover class from all other anchors when hovering an anchor. The second event covers the removal of the hover class when exiting the whole menu. Without this second event the last anchor hovered when moving away from the menu is left with the <code>.hover</code> class.</p> <p><a href="http://jsfiddle.net/Wu8QJ/1/" rel="nofollow"><strong>Updated demo</strong></a></p> <p>JavaScript</p> <pre><code>var $anchors = $('#menu a'); $('#menu').on('mouseenter', 'a', function() { $anchors.not(this).removeClass('hover'); var $this = $(this); if ($this.hasClass('hover')) return; $this.addClass('hover').effect('slide'); // EFFECT }); $('#menu').on('mouseleave', function() { $anchors.removeClass('hover'); });​ </code></pre> <p>CSS</p> <pre><code>#menu { background-color: black; } #menu a { display: block; color: white; } #menu a.hover { background-color:white; color:black; }​ </code></pre> <p>HTML</p> <pre><code>&lt;div id="menu"&gt; &lt;a href="#"&gt;Link 1&lt;/a&gt; &lt;a href="#"&gt;Link 2&lt;/a&gt; &lt;a href="#"&gt;Link 3&lt;/a&gt; &lt;/div&gt; </code></pre> <p>Hope this helps.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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