jquery实现倒计时小应用
本文实例为大家分享了jquery倒计时效果的具体代码,供大家参考,具体内容如下
html
小米Note顶配版
全网通香槟金移动联通
¥2998起
双4G手机双卡双待小米Note顶配版
全网通香槟金移动联通
¥2998起
双4G手机双卡双待
jquery
$(function(){
varabj=$("#shop_rec"),
timeObj=abj.find('.time');
varstarttime=timeObj.data('starttime');
//定时器函数
functionactionDo(){
returnsetInterval(function(){
timeObj.each(function(index,el){
vart=$(this),
surplusTime=t.data('endtime')-starttime;
if(surplusTime<=0){
t.html("活动已经开始");
}else{
varyear=surplusTime/(24*60*60*365),
showYear=parseInt(year),
month=(year-showYear)*12,
showMonth=parseInt(month),
day=(month-showMonth)*30,
showDay=parseInt(day),
hour=(day-showDay)*24,
showHour=parseInt(hour),
minute=(hour-showHour)*60,
showMinute=parseInt(minute),
seconds=(minute-showMinute)*60,
showSeconds=parseInt(seconds);
t.html("");
if(showYear>0){
t.append(""+showYear+"年")
};
if(showMonth>0){
t.append(""+showMonth+"月")
};
if(showDay>0){
t.append(""+showDay+"天")
};
if(showHour>=0){
t.append(""+showHour+"小时")
};
if(showMinute>=0){
t.append(""+showMinute+"分钟")
};
if(showSeconds>=0){
t.append(""+showSeconds+"秒")
};
};
});
starttime++;
},1000);//设定执行或延时时间
};
//执行它
actionDo();
});
总结
不是特别优秀,但是小的应用完全没有问题。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。