Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've created a <a href="http://jsfiddle.net/R8La6/" rel="nofollow noreferrer">Fiddle</a> that might be interesting. It is similar to the one in <a href="https://stackoverflow.com/questions/4318475/jquery-fading-problem/4318862#4318862">this</a> post with the difference that the names of the menu items are created on the fly. </p> <p>The code from the fiddle:</p> <pre><code>$("#menu li").hover( function() { if (!$(this).data("name")) { $(this).data("name", $('&lt;div class="name"&gt;&lt;/div&gt;') .text($(this).text()) .hide() .appendTo("#nameWrapper")); } $(this).data("name") .stop(true, true) .fadeIn(); }, function() { $(this).data("name") .stop(true, true) .fadeOut(); } ); </code></pre> <p>The idea is to have a name element for every menu item so you get a nice fade effect when the old name fades out and new one fades in at the same time. </p> <p>The first part of the first hover function creates a name element if there isn't one. The element is connected with the menu item using the <a href="http://api.jquery.com/data/" rel="nofollow noreferrer">data()</a> function.</p> <p>The second part of the first hover function just fades in the name element. The second function fades it out.</p> <p>The trick here is to use <a href="http://api.jquery.com/stop/" rel="nofollow noreferrer">stop(true, true)</a> to stop all animation on the element.</p> <p>EDIT: </p> <p>You start with a html structure like this one:</p> <pre><code>&lt;ul id="menu"&gt; &lt;li&gt;First&lt;/li&gt; &lt;li&gt;Second&lt;/li&gt; &lt;/ul&gt; &lt;div id="nameWrapper"&gt;&lt;/div&gt; </code></pre> <p>And after a couple of mouseover's over the menu items the nameWrapper div gets filled like so:</p> <pre><code>&lt;div id="nameWrapper"&gt; &lt;div class="name"&gt;First&lt;/div&gt; &lt;div class="name"&gt;Second&lt;/div&gt; &lt;/div&gt; </code></pre> <p>The div.name elements is what actually gets shown when you hover over the menu items. The div.name elements are created when you hover over the menu item for the first time, in the folowing code section:</p> <pre><code>$(this).data("name", // associate the &lt;div class="name"&gt; element with the menu item that is currently hovered - $(this) $('&lt;div class="name"&gt;&lt;/div&gt;') // create a div element .text($(this).text()) // set text inside div to text of the menu item .hide() // hide the div (it gets faded in later) .appendTo("#nameWrapper")); // append the element to the element with id nameWrapper </code></pre>
    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.
 

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