jQuery倒数每秒 [英] jQuery Countdown Each Second

查看:59
本文介绍了jQuery倒数每秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个jQuery倒数类型的动画,一旦它达到0,它就会执行一个函数.但是我遇到了问题,因为我不确定如何去做.我以为我会做一个while循环,然后暂停一秒钟,直到它达到0.但是似乎无法暂停while循环.所以我想知道什么是最好的方法?谢谢.

I'm trying to make a jQuery countdown type animation, that once it hits 0 it executes a function. However I'm having problems because I'm unsure how to go about doing this. I thought I'd do a while loop then pause for a second until it hits 0. However it doesn't seem possible to pause a while loop. So I'm wondering what's the best way to do this? Thanks.

推荐答案

代码:

var counter = 10;
var yourFunc = function(){}
var interval = setInterval(function(){
    counter--;
    if(counter <=0){ yourFunc(); clearInterval(interval); }
}, 1000);

这篇关于jQuery倒数每秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆