mildog8
mildog8

Reputation: 2154

.slideUp() after mouse been out for 2 seconds

I have a slide thing and I only want the #content div to slide up after the mouse has been out of .content for more than 2 seconds. but i want to be able to put my mouse back over, if it is within those 2 seconds. Here is the fiddle - http://jsfiddle.net/YZDGu/.

Upvotes: 0

Views: 2006

Answers (3)

sinemetu1
sinemetu1

Reputation: 1726

Updated your fiddle here with use of set/clearInterval.

See setInterval and clearInterval.

Upvotes: 1

Blender
Blender

Reputation: 298430

Use setTimeout and clearTimeout:

var slideTimer;

$(".container").hover(function(){
    $('#content').slideDown();
    clearTimeout(slideTimer);
},function(){
    slideTimer = setInterval(function() {
      $('#content').slideUp();
    }, 2000);
});

Demo: http://jsfiddle.net/GFpHH/

Upvotes: 4

Sagar Patil
Sagar Patil

Reputation: 1948

Add a delay:

$(".container").hover(function(){
        $(".container #content").slideDown();
},function(){
        $(".container #content").delay(2000).slideUp();
});

Upvotes: 1

Related Questions