溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

微信小程序動(dòng)態(tài)顯示項(xiàng)目倒計(jì)時(shí)效果

發(fā)布時(shí)間:2020-09-01 01:41:44 來(lái)源:腳本之家 閱讀:218 作者:PHP急先鋒 欄目:web開(kāi)發(fā)

本文實(shí)例為大家分享了微信小程序動(dòng)態(tài)顯示項(xiàng)目倒計(jì)時(shí)的具體代碼,供大家參考,具體內(nèi)容如下

1、一般我們說(shuō)的顯示秒殺都是指的單條數(shù)據(jù),循環(huán)我沒(méi)做。

效果:

微信小程序動(dòng)態(tài)顯示項(xiàng)目倒計(jì)時(shí)效果

2、wxml代碼:

<p>
<block wx:if="{{total_micro_second<=0}}">剩余時(shí)間:已經(jīng)截止</block>
<block wx:if="{{clock!='已經(jīng)截止'}}">剩余時(shí)間:{{clock}}</block>
</p>

3、.js文件代碼:

function countdown(that) {
 var EndTime = that.data.end_time || [];
 var NowTime = new Date().getTime();
 var total_micro_second = EndTime - NowTime || [];
 console.log('剩余時(shí)間:' + total_micro_second);
 // 渲染倒計(jì)時(shí)時(shí)鐘
 that.setData({
 clock: dateformat(total_micro_second)
 });
 if (total_micro_second <= 0) {
 that.setData({
 clock: "已經(jīng)截止"
 });
 //return;
 }
 setTimeout(function () {
 total_micro_second -= 1000;
 countdown(that);
 }
 , 1000)
 }

 // 時(shí)間格式化輸出,如11:03 25:19 每1s都會(huì)調(diào)用一次
 function dateformat(micro_second) {
 // 總秒數(shù)
 var second = Math.floor(micro_second / 1000);
 // 天數(shù)
 var day = Math.floor(second/3600/24);
 // 小時(shí)
 var hr = Math.floor(second/3600%24);
 // 分鐘
 var min = Math.floor(second/60%60);
 // 秒
 var sec = Math.floor(second%60);
 return day + "天" + hr + "小時(shí)" + min + "分鐘" + sec+"秒";
 }

Page({

 /**
 * 頁(yè)面的初始數(shù)據(jù)
 */
 data: {
 id:'',
 result:[],
 end_time:'',
 clock:''
 },/**
 * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載
 */
 onLoad: function (options) {
 var that = this;
 wx.request({
 url: 'https://m.******.com/index.php/Home/Xiaoxxf/activity_detail?a_id='+options.id,//不含富文本html
 data: {},
 method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
 header: {
 'Content-Type': 'application/json'
 },
 success: function (res) {
 that.setData({
 common: res.data, //一維數(shù)組,全部數(shù)據(jù)
 end_time: res.data.end_time //項(xiàng)目截止時(shí)間,時(shí)間戳,單位毫秒
 })
 console.log(that.data.common);
 console.log('結(jié)束時(shí)間:' + that.data.end_time);
 },
 fail: function (res) { },
 complete: function (res) { },
 }), 
//調(diào)用上面定義的遞歸函數(shù),一秒一刷新時(shí)間
 countdown(that);
},

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

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

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI