Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery: disappear div with delay; then appear/disappear on hover
    primarykey
    data
    text
    <p>I'm pretty new to jquery, and with what bits and pieces I've gathered, I've been trying to get a certain effect. <br><br><strong>Effect:</strong> Say I have some <code>#div</code>. Once the page loads, I want it to disappear after some delay, say 5000ms. But then I want it to show again in case of mouseover and disappear again on mouseout. <br><br><strong>So far:</strong> Like I said, I'm pretty new, so I may have made some silly error, or this problem may have a simple enough solution but I looked and didn't find one clear enough, so bear with me. I can get the two effects to work separately, not together.<br><br>To elaborate, using this code, I can hide the <code>#div</code> on page load and I'm thinking since the css just makes the div transparent rather than hide/display:none, I should be able to make it reappear with an opacity:1.<br>Also, the delay does not seem to be working. (I tried and it delays a fadeOut(), but I guess that means I won't be able to do much with that div again?)</p> <pre><code>$(document).ready( function() { $("#div") .fadeOut() .delay(5000) .queue(function() { $(this).css("opacity","0").dequeue(); }) }); </code></pre> <p>And I can make an "appear on mouseover + disappear on mouseout" effect using this:</p> <pre><code>$(document).ready(function(){ $("#div").hover(function(){ $("#div").css("opacity","1"); },function(){ $("#div").css("opacity","0"); }); }); </code></pre> <p>The main reason I've used opacity, as I said before, is because hiding the div won't let me make it reappear (as I understand). <BR><BR>So how can I combine the two effects? Any help is greatly appreciated.<br>Thanks in advance. <br> <hr> <strong>Update:</strong> For anybody interested/who stumbles upon this page later: @kkemple 's code below works perfectly; however I modified it slightly to show a nice delay after mouseout rather than a quick vanishing act. (There may be a better way to do this; this is just how I got it to work.)</p> <pre><code>$(document).ready( function() { $("#div").hover(function(){ $("#div").css("opacity","1"); },function(){ setTimeout(function(){ $("#div").animate({'opacity': 0}); },50); }); }); </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. 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