jquery 1.4.2 equivalent for setTimeout and clearTimeout
Is there any equivalent for setTimeout
and clearTimeout
functions in jquery 1.4.2.... I found this ex which uses jquery 1.3.2..
var alerttimer = window.setTimeout(function () {
$alert.trigger('click');
}, 3000);
$alert.animate({hei开发者_JAVA百科ght: $alert.css('line-height') || '50px'}, 200)
.click(function () {
window.clearTimeout(alerttimer);
$alert.animate({height: '0'}, 200);
});
setTimeout
and clearTimeout
are native JavaScript methods so they work in jQuery 1.4.2 also – and as such there is no need for equivalents in jQuery.
$(document.body).delay(3000).show(1, function(){
// do something
});
that would make use of jQuerys fx queuing to create a timeout. To emulate an interval in that manner, use a function which calls itself in the callback closure.
function repeat(){
// do something
$(document.body).delay(5000).show(1, repeat);
}
Use $(document.body).stop()
to clear the fx queue and stop the interval.
That works similiar to a javascript setTimeout
interval "hack".
(function(){
alert('I popup every 5 seconds! haha!');
setTimeout(arguments.callee, 5000);
})();
精彩评论