本文實(shí)例為大家分享了使用countdown插件實(shí)現(xiàn)倒計(jì)時(shí)的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)的效果如下:
這里實(shí)現(xiàn)的是一個(gè)活動(dòng)倒計(jì)時(shí),獲取當(dāng)前時(shí)間和活動(dòng)開始時(shí)間,相減得出的時(shí)間差就是我們需要的倒計(jì)時(shí)。愛掏網(wǎng) - it200.com使用插件很方便。愛掏網(wǎng) - it200.com
首先新建一個(gè)項(xiàng)目,選擇uni-app,模板選擇hello-uniapp,里面有官網(wǎng)的組件可以直接使用。愛掏網(wǎng) - it200.com創(chuàng)建之后將components整個(gè)文件夾復(fù)制到自己的項(xiàng)目中。愛掏網(wǎng) - it200.com
在需要使用倒計(jì)時(shí)的頁(yè)面引入組件
在頁(yè)面中放置定時(shí)器的位置
距開始剩
計(jì)算定時(shí)器中綁定的時(shí)間d,h,m,s
var date = new Date(); var now = date.getTime(); var star = this.myData.startTime var endDate = new Date(star); var end = endDate.getTime(); var leftTime = end-now; if (leftTime >= 0) { this.d = Math.floor(leftTime/1000/60/60/24); this.h = this.myData.validTime+Math.floor(leftTime/1000/60/60%24); this.m = Math.floor(leftTime/1000/60%60); this.s = Math.floor(leftTime/1000%60); console.log(this.d+'天'+this.h+'時(shí)'+this.m+'分'+this.s+'秒') }
完整代碼:
距開始剩
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持。愛掏網(wǎng) - it200.com?
聲明:所有內(nèi)容來(lái)自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。