vue 视频 时间进度条组件

article/2025/9/18 5:49:41

vue 视频 时间进度条组件
有些视频是以视频流的形式进行渲染的,没有视频滚动条,所以就写了24h的时间组件
在这里插入图片描述

在这里插入图片描述
实现思路:
1,24h的时间刻度线总宽度为12960px
2,点击24h线的某一点,获取这一点离左侧原点的距离(使用dom元素layerX和offsetLeft综合判断)
3,计算点击时线段的占比比率
4,每天的时间是86400000毫秒
5,占比比率乘以86400000就是获取的你点击的时间

代码如下:

<template><div class="time-main"><div class="center-content" ref="centerRef"><divref="timeRef"class="time-line"@click.capture="clickTimeLine($event)"><template v-for="(item, i) in timeArr"><div:key="'a' + i"class="base-line":style="{ left: 90 * i + 'px', height: 14 + 'px' }"></div><div :key="i" class="base-title" :style="{ left: 4 + 90 * i + 'px' }">{{ item }}</div><div:key="'b' + i"class="base-line":style="{ left: 18 + 90 * i + 'px' }"></div><div:key="'c' + i"class="base-line":style="{ left: 36 + 90 * i + 'px' }"></div><div:key="'d' + i"class="base-line":style="{ left: 54 + 90 * i + 'px' }"></div><div:key="'e' + i"class="base-line":style="{ left: 72 + 90 * i + 'px' }"></div></template></div></div><div class="btn-content"><div class="left-arow" @click="clickRightMove"><i class="el-icon-arrow-left"></i></div><div>{{ yesterdayTime | formatDateTime }}</div><div class="right-arow" @click="clickLeftMove"><i class="el-icon-arrow-right"></i></div></div></div>
</template>
<script>
import {compare,exactDiv,exactMul,exactSub,exactAdd,decimalsFormat,
} from "@/util/util.js";
export default {name: "timeLine",// inject: ["screenNum"],// watch: {//   screenNum: {//     handler(val) {//       console.log("切换了val==", val);//     },//   },// },props: {dateArr: {type: Array,},},data() {return {clickCnt: 0,leftMoveWidth: 0,endTimeFlag: false,timeArr: ["00:00","00:10","00:20","00:30","00:40","00:50","01:00","01:10","01:20","01:30","01:40","01:50","02:00","02:10","02:20","02:30","02:40","02:50","03:00","03:10","03:20","03:30","03:40","03:50","04:00","04:10","04:20","04:30","04:40","04:50","05:00","05:10","05:20","05:30","05:40","05:60","06:00","06:10","06:20","06:30","06:40","06:50","07:00","07:10","07:20","07:30","07:40","07:50","08:00","08:10","08:20","08:30","08:40","08:50","09:00","09:10","09:20","09:30","09:40","09:50","10:00","10:10","10:20","10:30","10:40","10:50","11:00","11:10","11:20","11:30","11:40","11:50","12:00","12:10","12:20","12:30","12:40","12:50","13:00","13:10","13:20","13:30","13:40","13:50","14:00","14:10","14:20","14:30","14:40","14:50","15:00","15:10","15:20","15:30","15:40","15:50","16:00","16:10","16:20","16:30","16:40","16:50","17:00","17:10","17:20","17:30","17:40","17:50","18:00","18:10","18:20","18:30","18:40","18:50","19:00","19:10","19:20","19:30","19:40","19:50","20:00","20:10","20:20","20:30","20:40","20:50","21:00","21:10","21:20","21:30","21:40","21:50","22:00","22:10","22:20","22:30","22:40","22:50","23:00","23:10","23:20","23:30","23:40","23:50",],switchWidthNum: 540,yesterdayTime: 0,clickTimeVal: 0,};},mounted() {// this.handleWidthFn();this.dealScrollMove();// console.log("mounted==", this.dateArr);},methods: {dealScrollMove() {if (this.$refs.centerRef.offsetWidth >= 540) {this.switchWidthNum = 540;} else if (this.$refs.centerRef.offsetWidth >= 360) {this.switchWidthNum = 360;} else if (this.$refs.centerRef.offsetWidth >= 270) {this.switchWidthNum = 270;} else if (this.$refs.centerRef.offsetWidth >= 180) {this.switchWidthNum = 180;} else {this.switchWidthNum = 90;}let time0 = new Date(new Date().toLocaleDateString()).getTime(); //获取当日0点时间戳let time1 = new Date().getTime(); // 当前时间let sumTimeWidth = 12960;let dayTimeSum = 86400000; //一天的毫秒数// if (this.clickTimeVal) {//   time1 = this.clickTimeVal;//   console.log("进==", time1);//   console.log("进=2=", this.clickTimeVal);// }if (this.dateArr.length > 0) {time1 = this.dateArr[0];time0 = exactSub(time0, dayTimeSum);console.log("进==", this.dateArr);console.log("进=2=", this.clickTimeVal);}let timeSub = exactSub(time1, time0);// console.log("timeSub=", timeSub);if (this.dateArr.length > 0) {this.yesterdayTime = this.dateArr[0];this.clickTimeVal = this.dateArr[0];} else {this.yesterdayTime = exactSub(time0, dayTimeSum);}let dayPer = exactDiv(timeSub, dayTimeSum); //一天的百分比console.log("exactDiv(timeSub, dayTimeSum)==", this.yesterdayTime);// console.log("dayPer==", dayPer);let scrollWidth = exactMul(sumTimeWidth, dayPer);// console.log("scrollWidth=333333=", scrollWidth);// console.log("scrollWidth=33333555553=", this.switchWidthNum);// 除以switchWidthNum 获取点击的个数let switchClickCnt = exactDiv(scrollWidth, this.switchWidthNum);// console.log("switchClickCnt==", switchClickCnt);this.clickCnt = parseInt(switchClickCnt) - 1;this.clickLeftMove();// console.log("点击的数量1===", this.clickCnt);},handleWidthFn() {this.$nextTick(() => {if (this.$refs.centerRef.offsetWidth >= 540) {this.switchWidthNum = 540;} else if (this.$refs.centerRef.offsetWidth >= 360) {this.switchWidthNum = 360;} else if (this.$refs.centerRef.offsetWidth >= 270) {this.switchWidthNum = 270;} else if (this.$refs.centerRef.offsetWidth >= 180) {this.switchWidthNum = 180;} else {this.switchWidthNum = 90;}});},clickTimeLine(event) {// console.log("event==", event);// console.log("event=layerX==", event.layerX);// console.log("event=layerX=target===", event.target.offsetLeft);let sumTimeWidth = 12960;let dayTimeSum = 86400000; //一天的毫秒数let time0 = new Date(new Date().toLocaleDateString()).getTime(); //获取当日0点时间戳let yesterdayTime = exactSub(time0, dayTimeSum);let timePointNum = 0;// className: "time-line"if (event.target.className == "time-line") {timePointNum = event.layerX;} else {timePointNum = exactAdd(event.layerX, event.target.offsetLeft);}let timemove = exactAdd(timePointNum, this.leftMoveWidth);let timePer = exactDiv(timemove, sumTimeWidth); // 点击的百分比let clickTimeNum = exactMul(dayTimeSum, timePer); //let trueTimeNum = exactAdd(clickTimeNum, yesterdayTime); // timelet fomretTime = parseInt(trueTimeNum);this.clickTimeVal = new Date(fomretTime).getTime();this.$emit("handleClickTimeLineFn",new Date(fomretTime));// console.log("trueTimeNum==", trueTimeNum);// console.log("fomretTime==", fomretTime);// console.log("new Date==", new Date(fomretTime));},clickLeftMove() {// console.log("点击的数量==2=", this.clickCnt);this.handleWidthFn();// console.log("this.$refs.centerRef==", this.$refs.centerRef);// console.log("centerRef=offsetWidth=", this.$refs.centerRef.offsetWidth);// console.log("centerRef=clientWidth=", this.$refs.centerRef.clientWidth);if (this.endTimeFlag) {return;}this.clickCnt++;this.leftMoveWidth = this.clickCnt * this.switchWidthNum;let letWidth = this.clickCnt * this.switchWidthNum + "px";// console.log(this.clickCnt);// console.log("this.$refs.timeRef==", this.$refs.timeRef);if (this.leftMoveWidth + this.$refs.centerRef.offsetWidth > 12960) {letWidth = 12960 - this.$refs.centerRef.offsetWidth + "px";this.endTimeFlag = true;} else {this.endTimeFlag = false;}this.$refs.timeRef.style.transform = "translateX(-" + letWidth + ")";this.$refs.timeRef.style.transition = "all 0.5s";},clickRightMove() {this.handleWidthFn();if (this.clickCnt > 0) {this.clickCnt--;}this.leftMoveWidth = this.clickCnt * this.switchWidthNum;let letWidth = this.clickCnt * this.switchWidthNum + "px";// console.log(this.clickCnt);// console.log("this.$refs.timeRef==", this.$refs.timeRef);if (this.endTimeFlag) {this.endTimeFlag = false;}this.$refs.timeRef.style.transform = "translateX(-" + letWidth + ")";this.$refs.timeRef.style.transition = "all 0.5s";},},
};
</script>
<style scoped lang="scss">
.time-main {position: relative;width: 100%;margin: auto;overflow: hidden;// display: flex;//   border: 1px solid red;
}
.center-content {width: calc(100% - 30px);margin-left: 30px;overflow: hidden;
}
.btn-content {width: calc(100% - 30px);margin-left: 30px;display: flex;justify-content: space-between;color: #fff;
}
.time-line {position: relative;font-size: 12px;/* left: -7357.15px; *///   left: 30px;height: 19px;width: 12960px;border-bottom: 1px solid rgb(90, 90, 90);margin: 0px;padding: 0px;transition: left 0.9s ease 0s;color: #fff;z-index: 10;&:hover {cursor: pointer;}.base-title {position: absolute;left: 4px;bottom: 3px;color: #fff;z-index: -1;}
}.base-line {position: absolute;width: 1px;height: 4px;bottom: 0px;background-color: rgb(90, 90, 90);z-index: 9;
}
.left-arow {// position: absolute;// left: 2%;color: #fff;font-size: 20px;
}
.right-arow {// position: absolute;// right: 2%;color: #fff;font-size: 20px;
}
</style>

http://chatgpt.dhexx.cn/article/bhsywT0C.shtml

相关文章

vue视频通话(Agora声网)

文章目录 声网简介语音视频通话API互动直播API实时消息API实时录制API实时码流加速API水晶球Agora Analytics 质量监控平台 基于声网实现视频通话注册配置实现音视频通话基本逻辑创建对象加入频道创建轨道订阅轨道 基于以上步骤封装组件导入注册使用项目页面注意事项GitHub链接…

vue 视频播放插件VideoPlayer

vue 视频播放插件VideoPlayer 1.npm install vue-video-player --save 2.main.js引入 import VideoPlayer from vue-video-player import vue-video-player/src/custom-theme.css import video.js/dist/video-js.cssVue.use(VideoPlayer)

vue 视频播放

一、概述 基于 Vue 的一个轻量级视频播放组件&#xff0c;适配 PC 和移动端。 官方链接&#xff1a;https://webweifeng.github.io/vue-mini-player/ 特色 1.轻量级 HTML5 播放器&#xff0c;精美 UI 控件&#xff0c;简单易上手 2.提供以 npm 的形式安装提供全局组件 3.多格式…

VUE视频

1.Vue后台脚手架安装过程&#xff1a;node.js

vue 视频截屏

video播放视频&#xff0c;一键截屏功能实现&#xff08;2种方式&#xff09; 1.canvas <template><div class"hik-box"><canvas style"display:none;width:200px;height:200px" id"myCanvas"></canvas><video wid…

Vue视频学习

黑马程序员vue前端基础教程-4个小时带你快速入门vue_哔哩哔哩_bilibili vue的el挂载点 id选择器&#xff0c;class选择器&#xff0c;元素选择器&#xff0c;推荐使用id选择器&#xff0c;因为id选择器唯一 vue的数据对象 vue开发网页&#xff1a; v-text v-html:解析返回的…

Vue2视频播放(Video)

Vue3视频播放&#xff08;Video&#xff09; 可自定义设置以下属性&#xff1a; 视频文件url&#xff08;src&#xff09;&#xff0c;必传&#xff0c;默认 &#xff0c;支持网络地址https和相对地址require(...) 视频封面url&#xff08;poster&#xff09;&#xff0c;默…

vue实现视频播放器功能,你学会了吗

&#x1f48c; 作者简介 &#x1f4d6; 个人介绍&#xff1a;小伙伴们&#xff0c;大家好&#xff01;我是水香木鱼&#xff0c;【前端领域创作者】&#x1f61c;&#x1f4dc; CSDN主页&#xff1a;水香木鱼&#x1f4d1; 个人博客&#xff1a;陈春波&#x1f3a8; 系列专栏&…

测试开发工程师成长日记001 - 敏捷测试、CI/CD/CT、DecOps的一些介绍

始终都没有很坚定想去做一份职业&#xff0c;大概就是缺少对互联网的热爱与坚持&#xff0c;对于我个人而言&#xff0c;大概需要的是简单而明确的方向&#xff0c;比如考研&#xff1a;选中一个学校并开始各个科目的学习和延伸。但是&#xff0c;找工作完全不一样&#xff0c;…

浅谈弱网测试及QNET

最近工作中需要进行弱网测试&#xff0c;所以在此将自己遇到的一些问题记录一下。本文是基于QNET进行的弱网测试。**首先弱网测试是什么&#xff1f;**模拟各种弱网环境&#xff0c;借助丢包、延时等弱网场景测试对弱网的处理机制&#xff0c;以游戏为例&#xff0c;就是保证前…

shell脚本测试

目录 test命令进行测试 1.比较大小 2.关于文件的权限检测&#xff08;-x常用&#xff09; 3.1测试文件是否存在&#xff08;-f&#xff0c;-d&#xff09; 4.多种条件的判断&#xff08;-a -o常用&#xff09; 5.判断字符串是否相等 expr命令 数值比较符号 逻辑判断脚本…

【Cmake】Ctest测试工具

目录 前言 一、初识CTest 二、使用方法 三、完整的简单测试工程 附录 附录一 cmake命令 enable_testing add_test 前言 原文&#xff1a;CTest - https://www.cnblogs.com/457220157-FTD/p/4139149.html 一、初识CTest CTest是CMake集成的一个测试工具&#xff0c;在使…

软件测试常见面试题

1、软件的含义 程序、数据以及相关文档的集合。 2、测试与调试的区别是什么&#xff1f; 测试是测试人员进行&#xff0c;主要目标是发现、报告、跟踪缺陷&#xff1b; 调试是开发人员进行&#xff0c;主要目标是定位缺陷位置、分析缺陷原因、修复缺陷。 3、IEEE是什么意思…

Web服务稳定性测试 负载测试 可靠性测试 方案 测试报告

注&#xff1a; 1. 程序员做的测试 2. 测试报告文档原稿在上传审核中&#xff0c;请等待 审核好了&#xff1a;https://download.csdn.net/download/yiquan_yang/12694138 1 概述 1.1 背景 系统的稳定性是系统长期稳定运行能力&#xff0c;需要时间累积才能度量。平台的某些问…

NFC测试

NFC功能点介绍&#xff1a; NFC英文全称Near Field Communication&#xff0c;近距离无线通信。 NFC采用主动和被动两种读取模式&#xff0c;NFC应用模式分为三种&#xff1a; 1、NFC卡模式&#xff08;被读模式&#xff0c;手机终端可以模拟成为一张普通的非接触卡被pos机读取…

Python 接口并发测试详解

一、接口并发测试简介 1、性能测试简介 性能测试是通过自动化测试工具模拟多种正常、峰值及异常负载条件对系统的各项性能指标进行的测试。负载测试和压力测试都属于性能测试,两者可以结合进行。通过负载测试,确定在各种工作负载下系统的性能,目标是测试当负载逐渐增加时,…

jmeter测试工具

文章目录 参考文章jmeter接口验签tomcat最大连接数jmeter参数彻底理解jmeter的ramp-up参数总结说明 持续时间的使用场景彻底理解ramp up2循环次数ramp-up线程数循环次数&#xff08;永远&#xff09;持续时间同步器里面的Timeout in milliseconds参数线程组参数 版本缺陷记录jm…

点餐系统测试

一、设计测试用例 二、提交BUG a)BUG 一 标题:兼容性差&#xff0c;只能在Chrome浏览器和火狐浏览器上使用 1.版本号&#xff1a;V0009 2.测试环境&#xff1a;Chrome 浏览器 版本号 96.0.4664.45 火狐 浏览器 版本号 97.0.1 操作系统&#xff1a;win10 3.测试数据…

接口 测试

一.接口概念 1.什么是接口(API) 接口:接口是为了提供一种服务 所有的接口统称为API,接口分为内部接口和外部接口 外部接口:测试被测系统和外部系统之间的接口 测试内部接口: 1.内部接口提供内部系统使用:开发人员自己开发的对自身系统提供的接口) 2.内部接口提供外部系统使用:…

Visual Studio 2017 15.8 正式发布,测试速度提高 82%

Visual Studio 2017 15.8 版本已正式发布&#xff1a; 发行说明&#xff1a;https://docs.microsoft.com/zh-cn/visualstudio/releasenotes/vs2017-relnotes#15.8下载地址&#xff1a;https://visualstudio.microsoft.com/downloads/ 安装 现可选择在开始安装之前下载所有安装文…