国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序實現商城倒計時

2024-07-22 01:18:11
字體:
來源:轉載
供稿:網友

本文實例為大家分享了微信小程序實現商城倒計時的具體代碼,供大家參考,具體內容如下

index.html:

<view class="countDownTimeView pull-left countDownAllView text-left">    <text>倒計時:</text>    <text class="voteText countDownTimeText">{{countDownHour}}</text> :    <text class="voteText countDownTimeText">{{countDownMinute}}</text> :    <text class="voteText countDownTimeText">{{countDownSecond}}</text> </view>

util.js :

const formatTime = date => {    const year = date.getFullYear()   const month = date.getMonth() + 1   const day = date.getDate()   const hour = date.getHours()   const minute = date.getMinutes()   const second = date.getSeconds()    return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') } const formatNumber = n => {   n = n.toString()   return n[1] ? n : '0' + n} module.exports = {   formatTime: formatTime}

index.js:

var util = require('../../utils/util.js');    //調用微信小程序中時間格式化的js Page: ({     data: {          countDownHour: 0, //倒計時 -時         countDownMinute: 0, //倒計時 -分         countDownSecond: 0, //倒計時-秒      },       // 頁面渲染后 執行     onLoad: function () {         //設置倒計時時間,1s變換一次        var interval = setInterval(function () {           var d = new Date();  //獲取系統日期和時間           var nowHour = d.getHours(); //小時           var nowMinutes = d.getMinutes(); //分           var nowSeconds = d.getSeconds(); //秒            // 顯示在倒計時中的小時位           var hour = 24 - nowHour;            // 顯示在倒計時中的分鐘位           var minutes = 60 - nowMinutes;            // 顯示在倒計時中的秒數           var seconds = 60 - nowSeconds;             //當小時、分鐘、秒都為0時,活動結束,倒計時顯示為00:00:00           if (hour == 0 && minutes == 0 && seconds == 0) {               clearInterval(interval);              wx.showToast({                title: '活動已結束',              });              console.log(totalSecond);               this.setData({                countDownHour: '00',                countDownMinute: '00',                countDownSecond: '00',              });           }             //當小時位、分鐘位、秒位小于10時,用字符串拼接的方式顯示,例如:06:08:02            if (hour < 10) {             hour = "0" + hour;           }           if (minutes < 10) {             minutes = "0" + minutes;           }           if (seconds < 10) {             seconds = "0" + seconds;           }           this.setData({             countDownHour: hour,             countDownMinute: minutes,             countDownSecond: seconds,           });        }.bind(this), 1000);   },})            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 滨州市| 盱眙县| 伊吾县| 娄底市| 翼城县| 乌海市| 郴州市| 德昌县| 庄浪县| 沭阳县| 浦城县| 浪卡子县| 合作市| 四子王旗| 新乡市| 贞丰县| 安丘市| 阜新| 衢州市| 长岭县| 江华| 拉萨市| 保康县| 宜兰市| 呈贡县| 乐至县| 永清县| 金坛市| 山阳县| 崇阳县| 永吉县| 江西省| 叶城县| 大连市| 山东省| 湄潭县| 福清市| 曲靖市| 乾安县| 临洮县| 满洲里市|