计时功能小程序要服务器吗,小程序实现正计时和倒计时-小程序实现倒计时-小程序倒计时功能...

1.

小程序实现正计时和倒计时1、正计时:2.

实现后的样式:3.

代码片段:vartimer;//计时器Page({data:{seconds:0,secondMax:3599,timeMax:'60:00',maxTime:'60:00',actionMax:true,stopMaxTime:false,resetMax:false,time:'00:00',cost:0,action:true,stopTime:false,reset:false,childName:[{"name":'选项1',"active":true},{"name":'选项2',"active":false},{"name":"选项3","active":false},{"name":'选项4',"active":false}],active1:false,active2:true,active3:false,active4:true,active:'Exercise-Program-choose-one'},cilckChild(e){constthatthis;letindexe.currentTarget.dataset.index;letchildNamethat.data.childName;for(leti0;ichildName.length;i++){if(indexi){childName[i].activetrue;}else{childName[i].activefalse;}}that.setData({childName:childName})},onLoad:function(options){},timing(e){this.setData({action:!this.data.action,stopTime:false})timing(this)},stopTime(e){console.log("现在的记录时间时长:"+this.data.seconds)this.setData({stopTime:true,reset:true})},reset(e){constthatthis;if(!that.data.reset){that.setData({stopTime:true})}else{that.setData({seconds:0,action:!that.data.action})}},timingMax(e){this.setData({actionMax:!this.data.actionMax,stopMaxTime:false})timingMax(this)},stopMaxTime(e){console.log("现在是记录的时间时长:",this.data.secondMax)this.setData({stopMaxTime:true,resetMax:true})},resetMax(e){constthatthis;if(!that.data.resetMax){that.setData({stopMaxTime:true})}else{that.setData({secondMax:3600,actionMax:!that.data.actionMax})}},functiontimingMax(that){varsecondsthat.data.secondMaxif(seconds0){that.setData({timeMax:'00:00'});return;}if(that.data.stopMaxTime){if(!that.data.resetMax){that.setData({secondMax:3600,actionMax:!that.data.actionMax})return;}return;}setTimeout(function(){that.setData({secondMax:seconds-1});timingMax(that);},1000)formatSecondsMax(that)}functionformatSecondsMax(that){varmins60,hours1,secondsthat.data.secondMax,timeMax''if(seconds60){minsparseInt(mins%60)}elseif(seconds3600){minsparseInt(seconds/60)secondsseconds%60}else{minsparseInt(seconds/60)secondsseconds%60hoursparseInt(mins/60)minsmins%60}console.log(formatTime(mins))console.log(formatTime(seconds))that.setData({//time:formatTime(hours)+':'+formatTime(mins)+':'+formatTime(seconds)timeMax:formatTime(mins)+':'+formatTime(seconds)});}functionformatTime(num){if(num10)return'0'+numelsereturnnum+''}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值