$("#date_1").hover(
function () {
var $this = $(this);
$this.addClass("door");
setTimeout(function() {
$this.addClass("doorstatic");
}, 2000); // 2000 is in mil sec eq to 2 sec.
},
function () {
$(this).removeClass("door doorstatic");
}
);
You can group your classes like removeClass("door doorstatic")
The problem here is that if you mouseover and before two seconds mouse out you will still have the class doorstatic
on you element.
The fix:
$("#date_1").hover(
function () {
var $this = $(this),
timer = $this.data("timer") || 0;
clearTimeout(timer);
$this.addClass("door");
timer = setTimeout(function() {
$this.addClass("doorstatic");
}, 2000); // 2000 is in mil sec eq to 2 sec.
$this.data("timer", timer);
},
function () {
var $this = $(this),
timer = $this.data("timer") || 0;
clearTimeout(timer);
$this.removeClass("door doorstatic");
}
);
Created a live example of the solution at jsFiddle.