最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序?qū)崿F(xiàn)商城倒計(jì)時(shí)

 更新時(shí)間:2020年11月01日 14:21:22   作者:刺鳥_前端  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)商城倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)商城倒計(jì)時(shí)的具體代碼,供大家參考,具體內(nèi)容如下

index.html:

<view class="countDownTimeView pull-left countDownAllView text-left">
 
 <text>倒計(jì)時(shí):</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'); //調(diào)用微信小程序中時(shí)間格式化的js
 
Page: ({
 
 data: {
 
   countDownHour: 0, //倒計(jì)時(shí) -時(shí)
   countDownMinute: 0, //倒計(jì)時(shí) -分
   countDownSecond: 0, //倒計(jì)時(shí)-秒
 
  },
 
 
 
 // 頁(yè)面渲染后 執(zhí)行
 
 onLoad: function () {
 
  //設(shè)置倒計(jì)時(shí)時(shí)間,1s變換一次
  var interval = setInterval(function () {
   var d = new Date(); //獲取系統(tǒng)日期和時(shí)間
   var nowHour = d.getHours(); //小時(shí)
   var nowMinutes = d.getMinutes(); //分
   var nowSeconds = d.getSeconds(); //秒
 
   // 顯示在倒計(jì)時(shí)中的小時(shí)位
   var hour = 24 - nowHour;
 
   // 顯示在倒計(jì)時(shí)中的分鐘位
   var minutes = 60 - nowMinutes;
 
   // 顯示在倒計(jì)時(shí)中的秒數(shù)
   var seconds = 60 - nowSeconds;
 
 
   //當(dāng)小時(shí)、分鐘、秒都為0時(shí),活動(dòng)結(jié)束,倒計(jì)時(shí)顯示為00:00:00
   if (hour == 0 && minutes == 0 && seconds == 0) {
 
    clearInterval(interval);
    wx.showToast({
    title: '活動(dòng)已結(jié)束',
    });
    console.log(totalSecond);
 
    this.setData({
    countDownHour: '00',
    countDownMinute: '00',
    countDownSecond: '00',
    });
   }
 
 
   //當(dāng)小時(shí)位、分鐘位、秒位小于10時(shí),用字符串拼接的方式顯示,例如: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);
 },
})

最終實(shí)現(xiàn)效果圖如下:

為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

穆棱市| 松潘县| 云南省| 澳门| 双峰县| 甘南县| 保德县| 营山县| 淳化县| 平江县| 郧西县| 阜阳市| 甘南县| 莱西市| 慈溪市| 读书| 凤翔县| 郓城县| 建德市| 兴海县| 宜城市| 冀州市| 嘉定区| 调兵山市| 都兰县| 天峨县| 龙胜| 长宁区| 开远市| 苍南县| 油尖旺区| 房产| 富阳市| 安仁县| 北宁市| 梓潼县| 阿克陶县| 澄江县| 霍山县| 汤阴县| 双柏县|