Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show div for 10 seconds and then hide it

Tags:

I have div block which comes on a mouseover of another div.

div1 img // mouse over shows div2.

I want to show div2 for 10 seconds and then hide it , can you please tell me how to achive this

Thanks

like image 361
kobe Avatar asked Nov 08 '10 20:11

kobe


People also ask

How do you hide a div after a few seconds?

Select the div element. Use delay function (setTimeOut(), delay()) to provide the delay to hide() the div element.

How do I show divs after 10 seconds?

fadeOut(10);" is enough).

How do you show divs after 5 seconds?

If you want to make a unobstrusive feature, you should let the div visible by default. When the page is correctly loaded, the first task to do is to hide the DIV with jQuery, and then, run an animation to show it in 5s. By doing this way, if there is no JS activated, the DIV is already available. Save this answer.


2 Answers

Use jQuery's delay(n); method http://api.jquery.com/delay/

 $(function() {
      $("#div1 img").hover(function(){
        $("#div2").show().delay( 10000 ).hide(0);
      });
    });
like image 27
FatherStorm Avatar answered Sep 30 '22 04:09

FatherStorm


$("#div1").mouseenter(function() {
    var $div2 = $("#div2");
    if ($div2.is(":visible")) { return; }
    $div2.show();
    setTimeout(function() {
        $div2.hide();
    }, 10000);
});

Another way to go:

$("#div1").mouseenter(function() {
    var $div2 = $("#div2");
    if ($div2.data("active")) { return; }
    $div2.show().data("active", true);
    setTimeout(function() {
        $div2.hide().data("active", false);
    }, 10000);
});
like image 192
Šime Vidas Avatar answered Sep 30 '22 04:09

Šime Vidas