小程序自定义长按说话进度条

虽然小程序有提供progress进度条,但在进度过程中停顿效果不好,所以自定义了一个
在这里插入图片描述

<view class="speaking">
    <view style="position:relative;width:686rpx;">
      <view class="currentsecond">
        <image src="/speak/imgs/wave.png"></image>
        <text>{{currentsecond}}"</text>
      </view>
      <!-- <progress percent="{{currentsecond}}" active stroke-width="28" duration="1" color="#0088FF" border-radius="14" active-mode="forwards"/> -->
      <view class="progress">
        <view class="currentprogress" style="width:{{currentprogress}}rpx"></view>
      </view>
      <text class="cantotal">60s</text>
    </view>
    <view class="remark">请长按说话</view>
    <view class="speakbtn {{touching?'touching':''}}" bindlongpress="speaking" bindtouchend="shutup" bindtouchstart="touch">
      <image src="/speak/imgs/whitemicrophone.png"></image>
    </view>
    <image class="closebtn" src="/speak/imgs/cha.png"></image>
  </view>
.speaking {
  padding: 64rpx 32rpx;
  background: #fff;
}

.currentsecond image {
  width: 20rpx;
  height: 26rpx;
  margin-left:26rpx;
  margin-right:18rpx;
}

.currentsecond {
  color: #fff;
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  height:56rpx;
  align-items: center;
}
.cantotal{
  position:absolute;
  right:0;
  top:0;
  display: inline-block;
  height: 56rpx;
  line-height: 56rpx;
  color:#999;
  margin-right:20rpx;
  font-size: 28rpx;
}
.remark{
  font-size: 24rpx;
  color:#999;
  text-align: center;
  margin:54rpx 32rpx;
}
.speakbtn{
  width:128rpx;
  height: 128rpx;
  background:#0088FF;
  border-radius: 50%;
  margin:0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform .2s;
}
.touching{
  transform: scale(0.95);
  transition: transform .2s;
  box-shadow: 0 0 8rpx #bbb inset;
  border:2rpx solid #343434;
  box-sizing: border-box;
}
.speakbtn image{
  width:44rpx;
  height: 64rpx;
}
.closebtn{
  width:28rpx;
  height:28rpx;
  position: absolute;
  bottom:58rpx;
  left:88rpx;
}
.progress{
  background: #F5F5F5;
  height: 56rpx;
  border-radius: 28rpx;
  overflow: hidden;
}
.currentprogress{
  background:#0088FF;
  height: 100%;
}
data: {
    currentsecond: 0,
    timer: '',
    tempCurrentone: 0,
    tempCurrenttwo: 0,
    currentprogress: 0,
    touching:false
  },
  shutup() {
    clearInterval(this.data.timer)
    this.setData({
      currentsecond: 0,
      currentprogress: 0,
      tempCurrentone: 0,
      tempCurrenttwo: 0,
      touching: false
    })
  },
  touch(){
    this.setData({
      touching:true
    })
  },
  speaking() {
    this.data.timer = setInterval(() => {
      this.data.tempCurrentone = Number(this.data.tempCurrentone + 1 / 100)
      this.data.tempCurrenttwo = this.data.tempCurrentone
      this.setData({
        currentsecond: (Number(this.data.tempCurrenttwo)).toFixed(),
        currentprogress: this.data.tempCurrentone / 60 * 686
      })
    }, 10)
  },
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值