微信小程序?qū)崿F(xiàn)時(shí)間進(jìn)度條功能
關(guān)于答題類(lèi),或者一些游戲環(huán)節(jié)的小程序需要用到時(shí)間進(jìn)度條,該功能怎么實(shí)現(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:"開(kāi)始" }, playbtn() { let that = this; let mark = that.data.mark; if (mark){ that.timer = setInterval(that.run, 1000); //that.timer關(guān)鍵點(diǎn) wx.showToast({ title: '開(kāi)始', }) that.setData({ mark:false, playPausetips:"暫停" }) }else{ clearInterval(that.timer); wx.showToast({ title: '暫停', }) that.setData({ mark: true, playPausetips: "開(kāi)始" }) } }, run(){ let that = this; let totalProgressTime = 60 //秒 let progressWidth = that.data.progressWidth; //顯示進(jìn)度 let progressTime = that.data.progressTime; //時(shí)間 if (progressWidth === 100) { wx.showToast({ title: '結(jié)束回調(diào)處理', }) clearInterval(that.timer); that.setData({ progressTime: totalProgressTime, //進(jìn)度條需要總時(shí)間s progressWidth: 100, //進(jìn)度100% progressTime: 60 }) return; } progressTime--; progressWidth = (totalProgressTime - progressTime) * (100 / 60) that.setData({ progressWidth: progressWidth, progressTime: progressTime }) } })
為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開(kāi)發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 詳解微信小程序——自定義圓形進(jìn)度條
- 微信小程序?qū)崿F(xiàn)下載進(jìn)度條的方法
- 微信小程序?qū)崿F(xiàn)實(shí)時(shí)圓形進(jìn)度條的方法示例
- 微信小程序多音頻播放進(jìn)度條問(wèn)題
- 微信小程序自定義組件實(shí)現(xiàn)環(huán)形進(jìn)度條
- 微信小程序之圓形進(jìn)度條實(shí)現(xiàn)思路
- 微信小程序自定義音樂(lè)進(jìn)度條的實(shí)例代碼
- 微信小程序?qū)崿F(xiàn)圓形進(jìn)度條動(dòng)畫(huà)
- 微信小程序繪制半圓(弧形)進(jìn)度條
- 微信小程序?qū)崿F(xiàn)圓心進(jìn)度條
相關(guān)文章
JavaScript將對(duì)象數(shù)組按字母順序排序的方法詳解
這篇文章主要介紹了JavaScript如何將對(duì)象數(shù)組按字母順序排序,本文介紹了三種解決方案,if條件語(yǔ)句 + sort(),localeCompare() + sort(),Collator() + sort(),有感興趣的同學(xué)可以跟著小編一起來(lái)看看2023-07-07JavaScript 異步調(diào)用框架 (Part 5 - 鏈?zhǔn)綄?shí)現(xiàn))
在上一篇文章里面,我們?yōu)楫惒秸{(diào)用框架設(shè)計(jì)了一種鏈?zhǔn)秸{(diào)用方式,來(lái)增強(qiáng)異步調(diào)用隊(duì)列的代碼可讀性,現(xiàn)在我們就來(lái)編寫(xiě)實(shí)現(xiàn)這部分功能的代碼。2009-08-08JS中自定義定時(shí)器讓它在某一時(shí)刻執(zhí)行
寫(xiě)一個(gè)方法,讓它在某一時(shí)刻執(zhí)行,即需要在JS中寫(xiě)一個(gè)定時(shí)器,當(dāng)時(shí)間達(dá)到要求時(shí)間時(shí),需要執(zhí)行的方法自動(dòng)執(zhí)行,下面的示例大家可以參考下2014-09-09JS中FormData類(lèi)實(shí)現(xiàn)文件上傳
這篇文章主要為大家詳細(xì)介紹了JS中FormData類(lèi)實(shí)現(xiàn)文件上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03javascript從定義到執(zhí)行 你不知道的那些事
這篇文章主要介紹了javascript從定義到執(zhí)行,你不知道的那些事,感興趣的小伙伴們可以參考一下2016-01-01基于JavaScript實(shí)現(xiàn)手機(jī)短信按鈕倒計(jì)時(shí)(超簡(jiǎn)單)
在淘寶等購(gòu)物網(wǎng)站,我們都會(huì)看到一個(gè)發(fā)送短信倒計(jì)時(shí)的按鈕,究竟是如何實(shí)現(xiàn)的呢?下面小編通過(guò)本篇文章給大家分享一段代碼關(guān)于js實(shí)現(xiàn)手機(jī)短信按鈕倒計(jì)時(shí),需要的朋友參考下2015-12-12JavaScript實(shí)現(xiàn)存儲(chǔ)HTML字符串示例
這篇文章主要介紹了JavaScript存儲(chǔ)HTML字符串的具體實(shí)現(xiàn),需要的朋友可以參考下2014-04-04