亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信小程序實現(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ā)教程》小編為大家精心整理的,希望喜歡。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論