内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

如何在微信小程序中實(shí)現(xiàn)秒殺批量倒計(jì)時(shí)功能

這篇“如何在微信小程序中實(shí)現(xiàn)秒殺批量倒計(jì)時(shí)功能”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“如何在微信小程序中實(shí)現(xiàn)秒殺批量倒計(jì)時(shí)功能”文章吧。

創(chuàng)新互聯(lián)專注于做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、網(wǎng)頁設(shè)計(jì)、網(wǎng)站制作、網(wǎng)站開發(fā)。公司秉持“客戶至上,用心服務(wù)”的宗旨,從客戶的利益和觀點(diǎn)出發(fā),讓客戶在網(wǎng)絡(luò)營銷中找到自己的駐足之地。尊重和關(guān)懷每一位客戶,用嚴(yán)謹(jǐn)?shù)膽B(tài)度對(duì)待客戶,用專業(yè)的服務(wù)創(chuàng)造價(jià)值,成為客戶值得信賴的朋友,為客戶解除后顧之憂。

JS

  1. 模擬商品列表數(shù)據(jù) goodsList;

  2. 在 onLoad 周期函數(shù)中對(duì)活動(dòng)結(jié)束時(shí)間進(jìn)行提??;

  3. 建立時(shí)間格式化函數(shù) timeFormat;

  4. 建立倒計(jì)時(shí)函數(shù) countDown;

  5. 在 onLoad 周期函數(shù)的提取結(jié)尾執(zhí)行倒計(jì)時(shí)函數(shù) countDown。

倒計(jì)時(shí)函數(shù)詳解

  1. 獲取當(dāng)前時(shí)間,同時(shí)得到活動(dòng)結(jié)束時(shí)間數(shù)組;

  2. 循環(huán)活動(dòng)結(jié)束時(shí)間數(shù)組,計(jì)算每個(gè)商品活動(dòng)結(jié)束時(shí)間的倒計(jì)時(shí)天、時(shí)、分、秒;

  3. 用 setData 方法刷新數(shù)據(jù);

  4. 每個(gè)一秒執(zhí)行一次倒計(jì)時(shí)函數(shù) setTimeout(this.countDown,1000);

let goodsList = [
 {actEndTime: '2018-05-01 10:00:43'},
 {actEndTime: '2018-04-01 11:00:00'},
 {actEndTime: '2018-06-01 12:45:56'},
 {actEndTime: '2018-07-01 15:00:23'},
 {actEndTime: '2018-05-23 17:00:22'},
 {actEndTime: '2018-05-14 19:00:44'},
 {actEndTime: '2018-05-21 21:00:34'},
 {actEndTime: '2018-06-17 09:00:37'},
 {actEndTime: '2018-03-21 05:00:59'},
 {actEndTime: '2018-04-19 07:00:48'},
 {actEndTime: '2018-04-28 03:00:11'}
]
Page({
 data: {
 countDownList: [],
 actEndTimeList: []
 },
 onLoad(){
 let endTimeList = [];
 // 將活動(dòng)的結(jié)束時(shí)間參數(shù)提成一個(gè)單獨(dú)的數(shù)組,方便操作
 goodsList.forEach(o => {endTimeList.push(o.actEndTime)})
 this.setData({ actEndTimeList: endTimeList});
 // 執(zhí)行倒計(jì)時(shí)函數(shù)
 this.countDown();
 },
 timeFormat(param){//小于10的格式化函數(shù)
 return param < 10 ? '0' + param : param; 
 },
 countDown(){//倒計(jì)時(shí)函數(shù)
 // 獲取當(dāng)前時(shí)間,同時(shí)得到活動(dòng)結(jié)束時(shí)間數(shù)組
 let newTime = new Date().getTime();
 let endTimeList = this.data.actEndTimeList;
 let countDownArr = [];

 // 對(duì)結(jié)束時(shí)間進(jìn)行處理渲染到頁面
 endTimeList.forEach(o => {
  let endTime = new Date(o).getTime();
  let obj = null;
  // 如果活動(dòng)未結(jié)束,對(duì)時(shí)間進(jìn)行處理
  if (endTime - newTime > 0){
  let time = (endTime - newTime) / 1000;
  // 獲取天、時(shí)、分、秒
  let day = parseInt(time / (60 * 60 * 24));
  let hou = parseInt(time % (60 * 60 * 24) / 3600);
  let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
  let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
  obj = {
   day: this.timeFormat(day),
   hou: this.timeFormat(hou),
   min: this.timeFormat(min),
   sec: this.timeFormat(sec)
  }
  }else{//活動(dòng)已結(jié)束,全部設(shè)置為'00'
  obj = {
   day: '00',
   hou: '00',
   min: '00',
   sec: '00'
  }
  }
  countDownArr.push(obj);
 })
 // 渲染,然后每隔一秒執(zhí)行一次倒計(jì)時(shí)函數(shù)
 this.setData({ countDownList: countDownArr})
 setTimeout(this.countDown,1000);
 }
})

WXML

簡(jiǎn)單的布局和居中顯示。

<view class='tui-countdown-content' wx:for="{{countDownList}}" wx:key="countDownList">
 剩余
 <text class='tui-conutdown-box'>{{item.day}}</text>天
 <text class='tui-conutdown-box'>{{item.hou}}</text>時(shí)
 <text class='tui-conutdown-box'>{{item.min}}</text>分
 <text class='tui-conutdown-box tui-countdown-bg'>{{item.sec}}</text>秒
</view>

WXSS

page{background-color: #eee;}
.tui-countdown-content{
 height: 50px;
 line-height: 50px;
 text-align: center;
 background-color: #fff;
 margin-top: 15px;
 padding: 0 15px;
 font-size: 18px;
}
.tui-conutdown-box{
 display: inline-block;
 height: 26px;
 width: 26px;
 line-height: 26px;
 text-align: center;
 background-color: #000;
 color: #fff;
 margin: 0 5px;
}
.tui-countdown-bg{
 background-color: #DF0101;
}

以上就是關(guān)于“如何在微信小程序中實(shí)現(xiàn)秒殺批量倒計(jì)時(shí)功能”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

分享題目:如何在微信小程序中實(shí)現(xiàn)秒殺批量倒計(jì)時(shí)功能
文章鏈接:http://www.rwnh.cn/article8/gcgjop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、網(wǎng)站維護(hù)、網(wǎng)站改版、外貿(mào)建站、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)
新建县| 西安市| 南岸区| 扎囊县| 浪卡子县| 陕西省| 凌海市| 张掖市| 潜山县| 漳州市| 郑州市| 泉州市| 宕昌县| 石楼县| 抚宁县| 惠东县| 桑日县| 开远市| 本溪| 子洲县| 张家川| 得荣县| 苏尼特左旗| 白水县| 得荣县| 宣化县| 溆浦县| 宿松县| 兴海县| 洛浦县| 武威市| 周宁县| 古丈县| 萝北县| 卓尼县| 安仁县| 万盛区| 綦江县| 肇庆市| 汕尾市| 临朐县|