微信小程序中顯示倒計(jì)時(shí)代碼實(shí)例
wxml文件中:
<!--倒計(jì)時(shí) --> <view class="countDownTimeView countDownAllView" > <view class="voteText countDownTimeText">{{countDownDay}}天</view> <view class="voteText countDownTimeText">{{countDownHour}}時(shí)</view> <view class="voteText countDownTimeText">{{countDownMinute}}分</view> <view class="voteText countDownTimeText">{{countDownSecond}}秒</view> </view>
js文件中:
Page( { data: { windowHeight: 654, maxtime: "", isHiddenLoading: true, isHiddenToast: true, dataList: {}, countDownDay: 0, countDownHour: 0, countDownMinute: 0, countDownSecond: 0, }, //事件處理函數(shù) bindViewTap: function() { wx.navigateTo( { url: '../logs/logs' }) }, onLoad: function() { this.setData( { windowHeight: wx.getStorageSync( 'windowHeight' ) }); }, // 頁(yè)面渲染完成后 調(diào)用 onReady: function () { var totalSecond = 1505540080 - Date.parse(new Date())/1000; var interval = setInterval(function () { // 秒數(shù) var second = totalSecond; // 天數(shù)位 var day = Math.floor(second / 3600 / 24); var dayStr = day.toString(); if (dayStr.length == 1) dayStr = '0' + dayStr; // 小時(shí)位 var hr = Math.floor((second - day * 3600 * 24) / 3600); var hrStr = hr.toString(); if (hrStr.length == 1) hrStr = '0' + hrStr; // 分鐘位 var min = Math.floor((second - day * 3600 *24 - hr * 3600) / 60); var minStr = min.toString(); if (minStr.length == 1) minStr = '0' + minStr; // 秒位 var sec = second - day * 3600 * 24 - hr * 3600 - min*60; var secStr = sec.toString(); if (secStr.length == 1) secStr = '0' + secStr; this.setData({ countDownDay: dayStr, countDownHour: hrStr, countDownMinute: minStr, countDownSecond: secStr, }); totalSecond--; if (totalSecond < 0) { clearInterval(interval); wx.showToast({ title: '活動(dòng)已結(jié)束', }); this.setData({ countDownDay: '00', countDownHour: '00', countDownMinute: '00', countDownSecond: '00', }); } }.bind(this), 1000); }, //cell事件處理函數(shù) bindCellViewTap: function (e) { var id = e.currentTarget.dataset.id; wx.navigateTo({ url: '../babyDetail/babyDetail?id=' + id }); } })
效果圖:
以上所述是小編給大家介紹的微信小程序中顯示倒計(jì)時(shí)詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- 微信小程序 倒計(jì)時(shí)組件實(shí)現(xiàn)代碼
- 微信小程序動(dòng)態(tài)顯示項(xiàng)目倒計(jì)時(shí)效果
- 微信小程序倒計(jì)時(shí)功能實(shí)例代碼
- 微信小程序?qū)崿F(xiàn)團(tuán)購(gòu)或秒殺批量倒計(jì)時(shí)
- 微信小程序顯示倒計(jì)時(shí)功能示例【測(cè)試可用】
- 微信小程序?qū)崿F(xiàn)倒計(jì)時(shí)60s獲取驗(yàn)證碼
- 微信小程序倒計(jì)時(shí)功能實(shí)現(xiàn)代碼
- 詳解微信小程序用定時(shí)器實(shí)現(xiàn)倒計(jì)時(shí)效果
- 微信小程序?qū)崿F(xiàn)倒計(jì)時(shí)功能
- 微信小程序?qū)崿F(xiàn)答題倒計(jì)時(shí)
相關(guān)文章
JS選項(xiàng)卡動(dòng)態(tài)替換banner圖片路徑的方法
這篇文章主要介紹了JS選項(xiàng)卡動(dòng)態(tài)替換banner圖片路徑的方法,涉及javascript操作文件css樣式的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-05-05JS實(shí)現(xiàn)向表格中動(dòng)態(tài)添加行的方法
這篇文章主要介紹了JS實(shí)現(xiàn)向表格中動(dòng)態(tài)添加行的方法,涉及javascript針對(duì)表格行的動(dòng)態(tài)添加技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03JavaScript字符串_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
JavaScript中的字符串就是用''或""括起來(lái)的字符表示。下面通過(guò)本文給大家介紹JavaScript字符串的相關(guān)知識(shí),感興趣的朋友一起看看吧2017-06-06詳細(xì)談?wù)凧avaScript中循環(huán)之間的差異
JS循環(huán)語(yǔ)句也叫迭代語(yǔ)句,是一種特殊的語(yǔ)句,主要用于需要多次執(zhí)行的代碼塊,下面這篇文章主要給大家介紹了關(guān)于JavaScript中循環(huán)之間的差異的相關(guān)資料,需要的朋友可以參考下2021-08-08JavaScript實(shí)現(xiàn)復(fù)選框全選功能
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)復(fù)選框全選功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-04-04