html video 设置进度条不可拖动_进度条滚动效果Css3

de5910afd8ad8bc0a0d1db9a8f444113.png

效果:

bb588edcf756c3024e0b945968a19d65.png
Css3实现进度条展示效果https://www.zhihu.com/video/1184507155678535680

关键字:linear-gradient

第一步:需要给一个div的框框

<!

9e5ecedf3437c5ea3858c93b6ec466e7.png
一无所有的状态

第二步:填充渐变色

<!

027ac8cb5d1167355011ee2e1753d262.png

进度实现的实际效果是多个条纹叠加,然后倾斜一定的角度实现的,站在调试的角度演示一下:

b4b7fdef951bf15749ded9fef6a680f0.png
调试状态https://www.zhihu.com/video/1184513177374588928

侧翻一定的角度展示的效果就和下面的这个图片一样了

82304ea0c7bda81c442e5a347a1ecc96.png

多半情况下我们都会翻车。。。。。。。。。

733930dc9660057d919fb3a367ba4b24.png

这个时候要分析是不是自己设置得像素的尺寸出现了问题,为了更直观调试出我们最终需要展示的效果,我这里上传了一个效果渐变的调试过程:

a366e9501244be47ff35cecf1e9028e3.png
调试效果展示https://www.zhihu.com/video/1184517571230982144

最后我们只要来个神奇的循环位置移动即可实现简单的额进度效果(实在不敢说专业,拿得出手还要手动调试一波色彩)

@

你以为这样就结束了,然而多半还是会翻车,比如下面这种情况

50bd5872cf34c3e1fd09c7e7fd6b1ec8.gif

这可不是我录制的卡顿,而是没有完整走完一个周期,正确的周期应该是依据background-size的大小,否则导致循环不是一个完整周期,效果自然展示失败。

调试之后的最终效果:

d019e01d69da2e451edfd053f88cd4fe.gif

源代码获取(WX代号BAR_007)

如有兴趣欢迎关注:码农的技术分享 获取源代码

备注:源码有延迟 若无回复联系博主

48f794ad160326266c5b96b534bfcaf7.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现微信小程序video组件的进度条可拖拽功能,可以使用以下步骤: 1. 在.wxml文件中,使用video组件,并加上一个view容器作为进度条的背景,再加上一个view作为进度条的滑块,代码如下: ```html <video src="{{src}}" poster="{{poster}}" bindtimeupdate="timeUpdate"></video> <view class="progress-bar"> <view class="progress" style="width: {{progress}}%;"></view> <view class="progress-btn" style="left: {{btnLeft}}px;"></view> </view> ``` 2. 在.wxss文件中,设置进度条和滑块的样式: ```css .progress-bar { position: relative; height: 6px; background-color: #ddd; } .progress { position: absolute; top: 0; left: 0; height: 6px; background-color: #f00; } .progress-btn { position: absolute; top: -5px; left: 0; width: 10px; height: 16px; border-radius: 50%; background-color: #fff; border: 2px solid #f00; box-shadow: 0 0 2px #f00; transform: translateX(-50%); } ``` 3. 在.js文件中,定义一个data对象,包含视频的总时长、当前播放时间、进度条长度和滑块位置等信息: ```javascript data: { src: 'http://www.example.com/video.mp4', poster: 'http://www.example.com/poster.jpg', duration: 0, currentTime: 0, progress: 0, btnLeft: 0, } ``` 4. 在onLoad生命周期函数中,获取视频的总时长: ```javascript onLoad: function() { var that = this; wx.createVideoContext('myVideo', that).requestFullScreen(); wx.createVideoContext('myVideo', that).play(); wx.createVideoContext('myVideo', that).pause(); wx.createVideoContext('myVideo', that).seek(0); wx.createVideoContext('myVideo', that).play(); wx.createVideoContext('myVideo', that).on('loadedmetadata', function(res) { that.setData({ duration: res.duration }); }); }, ``` 5. 在timeUpdate事件回调函数中,更新当前播放时间和进度条长度以及滑块位置: ```javascript timeUpdate: function(e) { var that = this; var currentTime = e.detail.currentTime; var duration = that.data.duration; var progress = Math.floor(currentTime / duration * 100); var btnLeft = progress * 3.4 - 7; that.setData({ currentTime: currentTime, progress: progress, btnLeft: btnLeft }); }, ``` 6. 在进度条的view容器上,绑定touchstart、touchmove和touchend事件,实现滑动改变进度条长度和滑块位置: ```javascript touchstart: function(e) { var that = this; that.setData({ startX: e.touches[0].pageX, }); }, touchmove: function(e) { var that = this; var startX = that.data.startX; var moveX = e.touches[0].pageX; var distance = moveX - startX; var duration = that.data.duration; var progress = that.data.progress + distance / 340 * 100; if (progress < 0) { progress = 0; } else if (progress > 100) { progress = 100; } var currentTime = progress / 100 * duration; var btnLeft = progress * 3.4 - 7; that.setData({ progress: progress, currentTime: currentTime, btnLeft: btnLeft, startX: moveX, }); }, touchend: function(e) { var that = this; wx.createVideoContext('myVideo', that).seek(that.data.currentTime); }, ``` 通过以上步骤,就可以实现微信小程序video组件的进度条可拖拽功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值