Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery toggle hover items with hide delay
    primarykey
    data
    text
    <p>I put this code together from a snippet from somewhere else, so I may not be doing this very well. I have multiple div's that looks like this:</p> <pre><code>&lt;div class="services"&gt; &lt;p&gt;...&lt;/p&gt; &lt;ol class="serviceList" style="display: none;"&gt; &lt;li&gt; &lt;p&gt;service&lt;/p&gt; &lt;ul&gt; &lt;li&gt;service description&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; ... &lt;/ol&gt; &lt;/div&gt; </code></pre> <p>I want the <code>&lt;ol&gt;</code> to <code>slideDown</code> when the services <code>div</code> is hovered over. It needs a delay so that it doesn't vanish if the user mistakenly mouseout. BUT if they mouse over another services <code>div</code> then the visible one needs to go away immediately to make room for the new <code>serviceList</code> Here is what I have now:</p> <pre><code>$('.services').each(function () { var time = 800; var hideDelay = 1000; var hideDelayTimer = null; var beingShown = false; var shown = false; var trigger = $(this); var info = $('.serviceList', this); $([trigger.get(0),info.get(0)]).mouseover(function () { if (hideDelayTimer) clearTimeout(hideDelayTimer); if (beingShown || shown) { // don't trigger the animation again return; } else { info.addClass('active'); // reset position of info box beingShown = true; info.css('zindex','2') .slideDown(time, function() { beingShown = false; shown = true; }); } return false; }).mouseout(function () { if (hideDelayTimer) clearTimeout(hideDelayTimer); hideDelayTimer = setTimeout(function () { hideDelayTimer = null; info.css('zindex','0') .fadeOut( hideDelay, function () { shown = false; info.removeClass('active'); }); }, hideDelay); return false; }); }); </code></pre> <p>I have a poor understanding of scope so I don't know what the get(0) stuff is about. I've been trying to have an event on mouseover that checks if any other "serviceList" is <code>.active</code> and then hide it. That works, unless you switch between "services" too fast. Am even close to doing this right? </p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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. 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