国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序實現時間進度條功能

2024-07-22 01:19:20
字體:
來源:轉載
供稿:網友

關于答題類,或者一些游戲環節的小程序需要用到時間進度條,該功能怎么實現?看下面源碼

<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  }) } })

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 资阳市| 关岭| 雷州市| 霍林郭勒市| 清徐县| 乌拉特前旗| 建宁县| 湖北省| 安龙县| 梅州市| 枣庄市| 丰县| 八宿县| 呼玛县| 凤山市| 莱阳市| 金寨县| 如皋市| 宣汉县| 钟祥市| 南安市| 静乐县| 奉化市| 闻喜县| 柯坪县| 铜鼓县| 沧州市| 轮台县| 神木县| 睢宁县| 金门县| 阜宁县| 丰都县| 伊金霍洛旗| 沁源县| 玉环县| 平遥县| 信丰县| 石景山区| 高邑县| 元朗区|