jquery制做精致的倒計時特效
本文實例為大家分享了jquery做一個小的倒計時效果的代碼,供大家參考,具體內(nèi)容如下
html:
<div id="shop_rec"> <ul class="cf"> <li> <img src="image/goods.jpg" alt="小米 Note 頂配版" /> <div> <h5>小米 Note 頂配版</h5> <p>全網(wǎng)通 香檳金 移動聯(lián)通<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> <h5>小米 Note 頂配版</h5> <p>全網(wǎng)通 香檳金 移動聯(lián)通<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'); // 定時器函數(shù) function actionDo(){ return setInterval(function(){ timeObj.each(function(index, el) { var t = $(this), surplusTime = t.data('endtime') -starttime; if (surplusTime <= 0) { t.html("活動已經(jīng)開始"); } 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); // 設定執(zhí)行或延時時間 }; // 執(zhí)行它 actionDo(); });
本文由FungLeo原創(chuàng)
本文地址:http://blog.csdn.net/fungleo/article/details/49446887
總結(jié)
不是特別優(yōu)秀,但是小的應用完全沒有問題。
精彩專題分享:js實現(xiàn)倒計時功能匯總
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助。
相關文章
jQuery+formdata實現(xiàn)上傳進度特效遇到的問題
這篇文章主要介紹了jQuery+formdata實現(xiàn)上傳進度特效遇到的問題的相關資料,需要的朋友可以參考下2016-02-02基于jQuery的網(wǎng)頁影音播放器jPlayer的基本使用教程
這篇文章主要介紹了基于jQuery的網(wǎng)頁影音播放器jPlayer的基本使用教程,文中的示例主要針對其播放音頻文件的用法,需要的朋友可以參考下2016-03-03jQuery基于json與cookie實現(xiàn)購物車的方法
這篇文章主要介紹了jQuery基于json與cookie實現(xiàn)購物車的方法,涉及jQuery操作json格式數(shù)據(jù)與cookie存儲購物車信息的相關技巧,需要的朋友可以參考下2016-04-04jquery實現(xiàn)點擊彈出可放大居中及關閉的對話框(附demo源碼下載)
這篇文章主要介紹了jquery實現(xiàn)點擊彈出可放大居中及關閉的對話框,具有可拖動、放大、居中及關閉等功能,提供了2種對話框模式供讀者選擇,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2016-05-05