Countdown - applet version

Countdown principle is very simple, himself a native to do so, a dozen lines to a plug-in package (applet wepy version)

Demand: the goods within 24 hours free, appropriate purchase button should also be free of style,

Implementation: the back-end deadline to return the goods free time, front desk to get the deadline, the deadline to get the current time and make the difference, when relations get every minute of the countdown!

Man of few words said on the code:

. 1  countDownCtrl () {
 2      the let DEADLINE = new new a Date (2019,5,25,19,30,0) // free deadline, beginning at month 0, the analog data is turned off 
. 3      the setInterval (() => {
 . 4          the let = curTime new new a Date () the getTime ().
 . 5  
. 6        the let deadline.getTime time = () - curTime   // remaining milliseconds 
. 7        the let RemainTime = the parseInt (time / 1000) // total remaining time in seconds
 . 8  
. 9        the let day = parseInt (remainTime / (24 * 3600)) // remaining days
 10        the let hour = the parseInt ((RemainTime-day 24 * * 3600) / 3600) h // remaining
 11       let minute =  parseInt((remainTime-day*24*3600-hour*3600)/60)//剩余分钟
12       let sec = parseInt(remainTime%60)//剩余秒
13 
14       hour = hour < 10 ? '0' + hour : hour;
15       minute = minute < 10 ? '0' + minute : minute
16       sec = sec < 10 ? '0' + sec : sec
17       let countDownText = hour+ ":" +minute+ ":" +sec
18       this.countDown = countDownText;
19       this.$apply()
20    },1000); 
21}

Principle is very simple, you can read it over twice to understand.

Renderings: 

 

Guess you like

Origin www.cnblogs.com/fanghl/p/11078894.html