jquery 1.4.2 相当于 setTimeout 和clearTimeout

发布于 2024-09-06 16:47:54 字数 471 浏览 1 评论 0原文

jquery 1.4.2 中是否有 setTimeoutclearTimeout 函数的等效项...我发现这个 ex 使用 jquery 1.3.2..

var alerttimer = window.setTimeout(function () {
            $alert.trigger('click');
            }, 3000);
            $alert.animate({height: $alert.css('line-height') || '50px'}, 200)
            .click(function () {
              window.clearTimeout(alerttimer);
              $alert.animate({height: '0'}, 200);
            });

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({height: $alert.css('line-height') || '50px'}, 200)
            .click(function () {
              window.clearTimeout(alerttimer);
              $alert.animate({height: '0'}, 200);
            });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

残花月 2024-09-13 16:47:54

setTimeoutclearTimeout 是原生 JavaScript 方法,因此它们也可以在 jQuery 1.4.2 中工作,因此 jQuery 中不需要等效方法。

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.

心是晴朗的。 2024-09-13 16:47:54
$(document.body).delay(3000).show(1, function(){
    // do something
});

这将利用 jQuery 的 fx 队列来创建超时。要以这种方式模拟间隔,请使用在回调闭包中调用自身的函数。

function repeat(){
     // do something
     $(document.body).delay(5000).show(1, repeat);
}

使用 $(document.body).stop() 清除 fx 队列并停止间隔。

这与 javascript setTimeout 间隔“hack”类似。

(function(){
    alert('I popup every 5 seconds! haha!');
    setTimeout(arguments.callee, 5000);
})();
$(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);
})();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文