微信小程序自定义进度条及手动拖拽功能

发布时间:2026/10/24 13:04:13
微信小程序自定义进度条及手动拖拽功能 首先是wxml部分view classproess-box view classtime{{currentTime}}/view movable-area catchtouchmovevoidMethod catchtaptap classprogress-box stylewidth:{{width}}px;height:10px view classbg-box view stylewidth:{{value}}% classinner/view /view movable-view classprogress-dot wx:if{{showDot}} x{{(value/100)*width}} bindtouchmovetouchmove bindtouchendtouchend directionhorizontal bindchangegetCgh view classdot/view /movable-view /movable-area view classend-time time styleleft: {{width548}}px{{duration}}/view /view使用movable-area 滑块组件定义 已播放部分movable-view 定义进度条总长度wxss定义样式.proess-box{ position: relative; bottom: 30rpx; } .proess-box .time { line-height: 20rpx; color: #fff; font-size: 20rpx; position: absolute; left: 12rpx; } .progress-box{ position: absolute; left: 54px; } .progress-dot{ background: #ffffff00; height:40px; display: flex; justify-content: center; align-items: center; top: -15px; z-index: 10; } .dot{ background: #ffffff; width: 8px; height:8px; border-radius: 50%; } .bg-box{ position: absolute; width: 100%; height: 2px; top: 4px; background-color: #ffffff22; } .bg-box .inner{ background:linear-gradient(to bottom,#ffffff,#666); height: 100%; }json{ component: true, usingComponents: {} }js部分Component({ properties: { value:{ type:Number, value:0, observer:function observe(){ var newVal arguments.length 0 arguments[0] ! undefined ? arguments[0] : {}; } }, showDot:{ type:Boolean, value:false }, duration:{ type: String, value: 00:00 }, currentTime: { type: String, value: 00:00:00 } }, data: { width: wx.getSystemInfoSync().windowWidth*0.6, currX:0, touch:false, timer:0 }, methods: { //这是bindchange触发的函数 getCgh(e){ let {x}e.detail let {width}this.data let pecentx/width*100 this.data.currXpecent }, tap(e){//点击区域的某处直接跳到那个进度 console.log(tap e, e.detail) let {x}e.detail let {width}this.data let pecent(x-54-8)/width*100 this.data.currXpecent this.triggerEvent(change,{value:pecent}) this.triggerEvent(changend,{value:pecent}) }, voidMethod(){}, touchmove(e){ this.triggerEvent(change,{value: this.data.currX}) // console.log(this.data.currX) }, touchend(e){ this.triggerEvent(change,{value: this.data.currX}) this.triggerEvent(changend,{value: this.data.currX}) }, } });进度条的使用progress value{{progress}} bindchangingshowTime showDot{{showDot}} currentTime{{currentTime}} duration{{duration}} bindchangechangeProgress bindchangendprogressChangend /progress手动拖拽功能data{ videoDuration: 0, // 视频总时长 duration: , // 视频总时长 00:00 currentTime: , // 播放时间 格式 00:00 progress: 0, // 视频进度条 progressState: true, //拖拽过程中不允许更新进度条 } /** * 拖动 视频 进度条 */ changeProgress: function(e) { const {videoDuration} this.data const {value} e.detail // 百分比 const time this.formatSeconds((value/100)*videoDuration) this.setData({progress: value, progressState: false, currentTime: time}) }, /** * 视频 进度条 拖动停止 */ progressChangend: function(e) { const {videoDuration} this.data const {value} e.detail // 百分比 const time (value/100)*videoDuration const q wx.createVideoContext(video, this) q.seek(time) this.setData({progressState: true}) }, bindtimeupdate: function (e) { const {currentTime, duration} e.detail const {progressState} this.data // 进度条 const progress (currentTime/duration)*100 // 拖动过程中不让进度条更新 if(progressState) { this.setData({progress: progress}) } },

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询