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
Select the div element. Use delay function (setTimeOut(), delay()) to provide the delay to hide() the div element.
fadeOut(10);" is enough).
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.
Use jQuery's delay(n); method http://api.jquery.com/delay/
$(function() {
$("#div1 img").hover(function(){
$("#div2").show().delay( 10000 ).hide(0);
});
});
$("#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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With