`
lishiguang
  • 浏览: 191549 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

用JS实现活动即将开始的读秒效果.

 
阅读更多

用JS实现活动即将开始的读秒效果.

 

var sh; //定义定时器

var beginTime,endTime; //定义服务器端的活动起始时间 和 结束时间

var times=0; // 定义随时间流逝的时间数

//调用

function rushPurchaseDiv(){

fresh();

//定义1秒刷一次

sh=setInterval(fresh,1000);

}

 

//刷新DIV代码

function fresh(){

++times;

//var begintime=new Date();

var begintime=new Date(Date.parse(beginTime));

var endtime=new Date(Date.parse(endTime));

var leftsecond=parseInt((endtime.getTime()-begintime.getTime())/1000);

leftsecond-=times;

d=parseInt(leftsecond/3600/24);

h=parseInt((leftsecond/3600)%24);

m=parseInt((leftsecond/60)%60);

s=parseInt(leftsecond%60);

rushPurchaseStr='还有'+d+'天'+h+'小时'+m+'分'+s+'秒 开始抢购!' ;

$("#rushPurchase").html(rushPurchaseStr);

if(leftsecond<=0){

rushPurchaseStr='抢购正在进行中...';

$("#rushPurchase").html(rushPurchaseStr);

clearInterval(sh);

}

}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics