html video 设置进度条不可拖动_vue实战开发017:一个简单的进度条模拟安全检测

今天做一个简单的检测进度条模拟,我们在很多平台都可以看到安全进度检测的进度条,实际是对我们的安全设置进行检查,当我们将对应的信息补全之后,就相当于完成了一项任务,其安全系数就会提升,这里我先整个最简单的进度条,下面是演示结果。

0f14cadbdfcfd11737dd6457699ec935.gif

首先我们来定义HTML,这里我们主要有进度条背景,进度条,分值和检测按钮,这个前台比较简单,当然也可以哪来用,这样的话后台要操作的就比较多了,计算和检测的活都交给了后台,我们只需要把后台传回来的数据显示在这里即可。

faeafecbeb37d1504624f95ee28ef116.png

接下来写CSS样式,这里我们还是喜欢使用响应式来布局我的设计,所以我用到了媒体查询功能,下面是CSS样式设置,pragressContainer控制整个进度条的样式,pragressbar则是进度条背景设置,pragress是进度条进度控制,这里绑定了一个动态的样式,来改变我们的进度。

6dfee72df1974ac34b8f2d3881ed3c8e.png

这里我模拟一个点击事件,来改变progress的值,这样进度条就会随着progress的增长,来改变style的width值实现进度改变的视觉,这里我定义一个num=0,然后写个定时器,让其自增,到了100就停止,再把num重置为0就可以反复检测了。

798ab533765ced99a650a614dfb06cf0.png

这个progress 值是检测的进度显示,如果想直接用的话就要通过后台来实时的传递这个值了,而检测结果result也需要通过后台处理完之后检测信息之后返回对应的结果,这样就把大部分压力抛给了后端了,这个比较简单,后面来慢慢完善。

8ecc29e5c2f5b1e7ae958c7de8c26048.png

这里用到了display: flex;这是W3C提出了一种新的布局方案,可以简便、完整、响应式地实现各种页面布局,我给进度条设定了flex: 1;它会自动的获取剩余空间宽度,这样我们在改变网页宽度时就可以自动调整宽度了,align-items: center;设定垂直居中显示。

40011e145d91189e43523c086d7ab008.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue Video.js是一个基于Vue.js和Video.js的HTML5视频播放器组件,可以帮助我们快速搭建一个美观实用的视频播放器。在Vue Video.js中,要实现进度条拖动,需要做以下几个步骤: 1.首先,在Vue Video.js中,可以通过vjs-player组件来实现视频播放功能,我们需要给这个组件添加ref属性,以便在后面使用。 2.在vjs-player的mounted生命周期中,我们可以通过this.$refs.player来获取到video.js的player对象,然后通过player.on方法来监听时间变化事件。 3.在监听事件中,可以获取到当前播放的时间和视频总时长,从而计算出当前进度条的位置。同时,也可以监听进度条的mousedown和mousemove事件,来实现进度条拖动的功能。 4.最后,在进度条拖动结束的时候,需要通过player.currentTime()方法来设置视频的当前播放时间。 下面是相关代码片段: ```vue <template> <div> <vjs-player ref="player" :options="playerOptions"></vjs-player> <div class="progress-bar-wrap"> <div class="progress-bar" ref="progressBar" @mousedown="onProgressBarMouseDown($event)"> <div class="progress-bar-inner" :style="{width: progressWidth}"></div> <div class="progress-bar-thumb" :style="{left: progressWidth}"></div> </div> </div> </div> </template> <script> export default { data() { return { playerOptions: { autoplay: false, controls: true, sources: [{ src: 'https://example.com/path/to/video.mp4', type: 'video/mp4' }] }, progressWidth: 0, isDragging: false } }, mounted() { const player = this.$refs.player.$player player.on('timeupdate', () => { const currentTime = player.currentTime() const duration = player.duration() this.progressWidth = `${(currentTime / duration) * 100}%` }) document.addEventListener('mousemove', this.onDocumentMouseMove) document.addEventListener('mouseup', this.onDocumentMouseUp) }, beforeDestroy() { document.removeEventListener('mousemove', this.onDocumentMouseMove) document.removeEventListener('mouseup', this.onDocumentMouseUp) }, methods: { onProgressBarMouseDown(event) { this.isDragging = true this.onDocumentMouseMove(event) }, onDocumentMouseMove(event) { if (!this.isDragging) return const progressBar = this.$refs.progressBar const rect = progressBar.getBoundingClientRect() const progressWidth = ((event.clientX - rect.left) / rect.width) * 100 this.progressWidth = `${Math.min(Math.max(progressWidth, 0), 100)}%` }, onDocumentMouseUp() { if (!this.isDragging) return const player = this.$refs.player.$player const duration = player.duration() player.currentTime(duration * (parseInt(this.progressWidth) / 100)) this.isDragging = false } } } </script> <style> .progress-bar-wrap { width: 100%; height: 8px; background-color: #f2f2f2; } .progress-bar { position: relative; width: 100%; height: 100%; cursor: pointer; } .progress-bar-inner { position: absolute; top: 0; left: 0; height: 100%; background-color: #00bfff; } .progress-bar-thumb { position: absolute; top: -5px; left: -8px; width: 16px; height: 16px; border-radius: 50%; background-color: #00bfff; } </style>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值