위챗 애플릿이 카운트다운 기능을 실현하다
상점 상품 중 이벤트 카운트다운
js
var endTime = new Date().getTime() + 24 * 3600 * 1000*4;
Page({
/**
*
*/
data: {
headerImgs: postData.postSwiperData,
countDownDay: '',
countDownHour: '',
countDownMinute: '',
countDownSecond: '',
},
/**
* --
*/
onLoad: function(options) {
var id = options.id; //
},
onReady: function() {
var that = this;
countdown(that);
}
})
function countdown(that) {
var NowTime = new Date().getTime();
var EndTime = endTime;
var total_micro_second = EndTime - NowTime || [];
console.log(' '+NowTime+'
:' + total_micro_second);
//
that.setData({
countDownDay: dateformaDay(total_micro_second),
countDownHour: dateformaHour(total_micro_second),
countDownMinute: dateformaMinute(total_micro_second),
countDownSecond: dateformaSecondMinute(total_micro_second),
});
// if (total_micro_second <= 0) {
// that.setData({
// clock: " "
// });
// //return;
// }
setTimeout(function() {
total_micro_second -= 1000;
countdown(that);
}, 1000)
}
//
function dateformaDay(micro_second) {
//
var second = Math.floor(micro_second / 1000);
//
var day = Math.floor(second / 3600 / 24);
return day;
}
function dateformaHour(micro_second) {
//
var second = Math.floor(micro_second / 1000);
//
var hr = Math.floor(second / 3600 % 24);
return hr;
}
function dateformaMinute(micro_second) {
//
var second = Math.floor(micro_second / 1000);
//
var min = Math.floor(second / 60 % 60);
return min;
}
function dateformaSecondMinute(micro_second) {
//
var second = Math.floor(micro_second / 1000);
//
var sec = Math.floor(second % 60);
return sec;
}
wxml
<!-- start -->
<view style='display:flex;flex-direction:column;'>
<span style="font-size:10px;color:white;margin-top:5px;"> </span>
<view class='time-container'>
<text class='time-number'>{{countDownDay}}</text>
<span class='time-text'> </span>
<text class='time-number'>{{countDownHour}}</text>
<span class='time-text'> </span>
<text class='time-number'>{{countDownMinute}}</text>
<span class='time-text '> </span>
<text class='time-number '>{{countDownSecond}}</text>
<span class='time-text '> </span>
</view>
</view>
<!-- end -->
wxss
.time-container {
display: flex;
flex-direction: row;
margin-top: 10px;
margin-bottom: 10px;
margin-right: 10px;
align-items: center;
}
.time-number {
background: white;
color: red;
width: 18px;
height: 18px;
font-size: 12px;
border-radius: 3px;
display: flex;
align-items: center;
justify-content: center;
}
.time-text {
font-size: 10px;
color: white;
margin: 3px;
}
여러분에게 현재 관심이 비교적 높은 위챗 소프로그램 강좌 한 편을 추천합니다《위챗 소프로그램 개발 강좌》. 여러분을 위해 정성스럽게 정리한 것이니 마음에 드셨으면 좋겠습니다.이상은 본문의 전체 내용입니다. 여러분의 학습에 도움이 되고 저희를 많이 응원해 주십시오.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
유니앱, 위챗 애플릿에서 MQTT 사용 문제(1)MQTT.js는 JavaScript로 작성된 MQTT 프로토콜의 클라이언트 라이브러리로 Node에 사용할 수 있습니다.js와 브라우저.노드에서.js단은 전역 설치를 통해 명령행 연결을 사용할 수 있으며 MQTT...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.