这篇文章主要为大家展示了“jquery如何实现倒计时小应用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“jquery如何实现倒计时小应用”这篇文章吧。
具体内容如下
html
<div id="shop_rec">
<ul class="cf">
<li>
<img src="image/goods.jpg" alt="小米 Note 顶配版" />
<div>
<h6>小米 Note 顶配版</h6>
<p>全网通 香槟金 移动联通<br />双4G手机 双卡双待</p>
<em>¥2998<i>起</i></em>
<span class="time" data-starttime="1445982375" data-endtime="1446350400"></span>
</div>
</li>
<li>
<img src="image/goods.jpg" alt="小米 Note 顶配版" />
<div>
<h6>小米 Note 顶配版</h6>
<p>全网通 香槟金 移动联通<br />双4G手机 双卡双待</p>
<em>¥2998<i>起</i></em>
<span class="time" data-starttime="1445912375" data-endtime="1436350400"></span>
</div>
</li>
</ul>
</div>
jquery
$(function(){
var abj = $("#shop_rec"),
timeObj = abj.find('.time');
var starttime = timeObj.data('starttime');
// 定时器函数
function actionDo(){
return setInterval(function(){
timeObj.each(function(index, el) {
var t = $(this),
surplusTime = t.data('endtime') -starttime;
if (surplusTime <= 0) {
t.html("活动已经开始");
} else{
var year = 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("<span>"+showYear+"年</span>")
};
if (showMonth>0) {
t.append("<span>"+showMonth+"月</span>")
};
if (showDay>0) {
t.append("<span>"+showDay+"天</span>")
};
if (showHour>=0) {
t.append("<span>"+showHour+"小时</span>")
};
if (showMinute>=0) {
t.append("<span>"+showMinute+"分钟</span>")
};
if (showSeconds>=0) {
t.append("<span>"+showSeconds+"秒</span>")
};
};
});
starttime++;
},1000); // 设定执行或延时时间
};
// 执行它
actionDo();
});
以上是“jquery如何实现倒计时小应用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网行业资讯频道!