您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“微信小程序中如何顯示倒計(jì)時(shí)”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“微信小程序中如何顯示倒計(jì)時(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' ) }); }, // 頁面渲染完成后 調(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í)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。