微信小程序實現(xiàn)時間進度條功能
更新時間:2020年11月17日 11:35:44 作者:£AP︶ㄣOL◢◤LO
這篇文章主要為大家詳細介紹了微信小程序實現(xiàn)時間進度條功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
關于答題類,或者一些游戲環(huán)節(jié)的小程序需要用到時間進度條,該功能怎么實現(xiàn)?看下面源碼
<view class='out' style='margin-top:10px'> <view class='in' style='width:{{progressWidth}}%'></view> </view> <view class='caozuo'> <text>{{progressTime}}秒</text> <text bindtap='playbtn' data-change='1'>{{playPausetips}}</text> </view>
CSS:
.out {margin-left:auto;margin-right:auto;width:250px;height:20px;border:1px solid red;border-radius:20px;overflow:hidden;} .in {height:100%;background-color:red;} .caozuo{font-size:14px;color:#333;margin-left:auto;margin-right:auto;width:250px;margin-top:10px;display: flex;justify-content:space-between}
JS:
Page({ data: { progressWidth:0, progressTime:60, mark:true, playPausetips:"開始" }, playbtn() { let that = this; let mark = that.data.mark; if (mark){ that.timer = setInterval(that.run, 1000); //that.timer關鍵點 wx.showToast({ title: '開始', }) that.setData({ mark:false, playPausetips:"暫停" }) }else{ clearInterval(that.timer); wx.showToast({ title: '暫停', }) that.setData({ mark: true, playPausetips: "開始" }) } }, run(){ let that = this; let totalProgressTime = 60 //秒 let progressWidth = that.data.progressWidth; //顯示進度 let progressTime = that.data.progressTime; //時間 if (progressWidth === 100) { wx.showToast({ title: '結束回調處理', }) clearInterval(that.timer); that.setData({ progressTime: totalProgressTime, //進度條需要總時間s progressWidth: 100, //進度100% progressTime: 60 }) return; } progressTime--; progressWidth = (totalProgressTime - progressTime) * (100 / 60) that.setData({ progressWidth: progressWidth, progressTime: progressTime }) } })
為大家推薦現(xiàn)在關注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
JavaScript將對象數(shù)組按字母順序排序的方法詳解
這篇文章主要介紹了JavaScript如何將對象數(shù)組按字母順序排序,本文介紹了三種解決方案,if條件語句 + sort(),localeCompare() + sort(),Collator() + sort(),有感興趣的同學可以跟著小編一起來看看2023-07-07JavaScript 異步調用框架 (Part 5 - 鏈式實現(xiàn))
在上一篇文章里面,我們?yōu)楫惒秸{用框架設計了一種鏈式調用方式,來增強異步調用隊列的代碼可讀性,現(xiàn)在我們就來編寫實現(xiàn)這部分功能的代碼。2009-08-08javascript從定義到執(zhí)行 你不知道的那些事
這篇文章主要介紹了javascript從定義到執(zhí)行,你不知道的那些事,感興趣的小伙伴們可以參考一下2016-01-01基于JavaScript實現(xiàn)手機短信按鈕倒計時(超簡單)
在淘寶等購物網(wǎng)站,我們都會看到一個發(fā)送短信倒計時的按鈕,究竟是如何實現(xiàn)的呢?下面小編通過本篇文章給大家分享一段代碼關于js實現(xiàn)手機短信按鈕倒計時,需要的朋友參考下2015-12-12