倒计时

2018-06-12  本文已影响0人  枫尘逍遥

(function(){

var time = $('#countdown').data('time');

if (time) {

var curTime = (new Date()).getTime();

var mss = time-curTime;

if(mss){

var intervalTime = 1000

            countDown()

setInterval(function(){

mss -= intervalTime

                countDown()

},intervalTime)

}else{

$('#countdown').html(0 + " 天 " + 0 + " 小时 " + 0 + " 分" + 0 + " 秒 ")

}

}

function countDown(){

var days = parseInt(mss / (1000 * 60 * 60 * 24));

var hours = parseInt((mss % (1000 * 60 * 60 * 24))/ (1000 * 60 * 60));

var minutes = parseInt((mss % (1000 * 60 * 60))/ (1000 * 60));

var seconds = parseInt((mss % (1000 * 60))/ 1000);

$('#countdown').html(days + " 天 " + hours + " 小时 " + minutes + " 分" + seconds + " 秒 ");

if(days==0&&hours==0&&minutes==0&&seconds==0){

$('#countdown').html(0 + " 天 " + 0 + " 小时 " + 0 + " 分" + 0 + " 秒 ")

}

}

})()

上一篇下一篇

猜你喜欢

热点阅读