自定义滑块Vue组件
<div class="audio">
<audio id="audio" ref="audio" src="http://www.w3school.com.cn/i/horse.ogg"></audio>
<div class="stopbtn" @click="play" v-if="flag"></div>
<div class="playbtn" @click="paused" v-else></div>
<div class="timebar" ref="timebare" @touchmove="timebarmove($event)" @click="clickbar($event)">
<div class="bar" ref="bar" @touchstart="touchstart($event)">
<span></span>
</div>
<div class="mask" ref="mask"></div>
</div>
<div class="time">{{ currentTime }} / {{ alltime }}</div>
</div>
data () {
return {
currentTime: 0,
statu: false,
ox: 0,
left: 0,
alltime: '',
state: false,
flag: true
}
},
mounted () {
var audio = document.getElementById('audio')
audio.addEventListener('canplay', () => {
this.alltime = audio.duration//获取总时长
})
},
methods: {
play () {
this.flag = false
let timer = setInterval(() => {
this.currentTime += 1
if (this.currentTime > this.alltime) {
clearInterval(timer)
this.currentTime = this.alltime
this.flag = true
this.currentTime = 0
}
this.$refs.bar.style.cssText = 'left:' + this.currentTime / this.alltime * 213 + 'px'
this.$refs.mask.style.cssText = 'width:' + this.currentTime / this.alltime * 213 + 'px'
}, 1000)
},
paused () {
this.flag = false
},
touchstart (e) {
this.ox = e.touches[0].pageX - this.left
this.statu = true
},
timebarmove (e) {
if (this.statu) {
this.left = e.touches[0].pageX - Number(this.ox)
if (this.left < 0) {
this.left = 0
}
if (this.left > 213) {
this.left = 213
}
this.$refs.bar.style.cssText = 'left:' + this.currentTime / this.alltime * 213 + 'px'
this.$refs.mask.style.cssText = 'width:' + this.currentTime / this.alltime * 213 + 'px'
}
},
clickbar (e) {
if (!this.statu) {
this.left = e.x - 82
if (this.left < 0) {
this.left = 0
}
if (this.left > 213) {
this.left = 213
}
this.$refs.bar.style.cssText = 'left:' + this.currentTime / this.alltime * 213 + 'px'
this.$refs.mask.style.cssText = 'width:' + this.currentTime / this.alltime * 213 + 'px'
}
},
touchend () {
this.statu = false
}
}
自定义滑块Vue组件的更多相关文章
- vue学习--自定义全局vue组件
文档目录: |--components |-loading(组件文件夹) |-loading.vue (loading组件核心) |-index.js //配置导出组件,并且install 主要配置到 ...
- Vue组件之自定义表单组件
今天又看了一遍vue的文档,记得之前学习的时候,官方文档中有提过,v-model指令是一个语法糖,做两件事,一个是给表单控件元素绑定value,第二个是当输入时更新绑定的值,不过后来在"表单 ...
- Vue组件绑定自定义事件
Vue组件使用v-on绑定自定义事件: 可以分为3步理解: 1.在组件模板中按照正常事件机制绑定事件: template: '<button v-on:click="increment ...
- vue 基础-->进阶 教程(2): 指令、自定义指令、组件
第二章 建议学习时间4小时 课程共3章 前面的nodejs教程并没有停止更新,因为node项目需要用vue来实现界面部分,所以先插入一个vue教程,以免不会的同学不能很好的完成项目. 本教程,将从零 ...
- vue-gemini-scrollbar(vue组件-自定义滚动条)
vue-gemini-scrollbar(vue组件-自定义滚动条) https://segmentfault.com/a/1190000013338560
- 自定义Vue组件打包、发布到npm以及使用
本文将帮助:将自己写的Vue组件打包到npm进行代码托管,以及正常发布之后如何使用自己的组件. 本文讲述的仅仅是最基础的实现,其他复杂的操作需要非常熟悉webpack的相关知识,作者将继续学习. 先附 ...
- vue组件、自定义指令、路由
1.vue组件 组件(Component)是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.组件系统让我们可以用独立可复用的小组件来构建大型应用,几乎任意类型的应用的 ...
- 自定义Vue组件
自定义Vue组件的三步骤 1.创建组件 2.注册组件 3.使用组件 创建组件 //创建组件 var myclock = { data(){ return { clock: new Date().toL ...
- Vue自定义Popup弹窗组件|vue仿ios、微信弹窗|vue右键弹层
基于vue.js构建的轻量级Vue移动端弹出框组件Vpopup vpopup 汇聚了有赞Vant.京东NutUI等Vue组件库的Msg消息框.Popup弹层.Dialog对话框.Toast弱提示.Ac ...
随机推荐
- python web框架之Tornado的简单使用
python web框架有很多,比如常用的有django,flask等.今天主要介绍Tornado ,Tornado是一个用Python写的相对简单的.不设障碍的Web服务器架构,用以处理上万的同时的 ...
- Xml Helper
类的完整代码: using System;using System.Collections;using System.Xml; namespace Keleyi.Com.XmlDAL{public c ...
- C语言数据结构-队列的实现-初始化、销毁、清空、长度、队列头元素、插入、删除、显示操作
1.数据结构-队列的实现-C语言 //队列的存储结构 #define MAXSIZE 100 typedef struct { int* base; //基地址 int _front; //头指针 i ...
- 洛谷 P1028 数的计算
嗯... 首先这道题想到的就是递推.... 但是递推失败 (不知道自己是怎么想的 然后又想打一个暴力,但是数的最高位太难存储了,所以又放弃了(并且好像这个暴力大约500就会炸... 然后看了题解,才发 ...
- 黑马JavaScript学习一 BOM之Window对象定时器功能
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- java 常用操作(保留小数位数、int转string,string转int)
1.保留2位小数 //similarityTemp为double类型,需要保留2位有效数据,利用String.format String strTemp=String.format("%.2 ...
- shell编程中
1.1 条件表达式 1.1.1 文件判断 常用文件测试操作符 常用文件测试操作符 说明 -d文件,d的全拼为directory 文件存在且为目录则为真,即测试表达式成立 -f文件,f的全拼为file ...
- tomcat启动非常慢
解决: 有两种解决办法: 1)在Tomcat环境中解决 可以通过配置JRE使用非阻塞的Entropy Source. 在catalina.sh中加入这么一行: JAVA_OPTS="-Dja ...
- 简述wcf应用
一.新建wcf 如下图:wcf可以简历俩种形式 1.库文件,就是一个类库文件,可以用windows服务或控制台开启. 2.服务应用程序,可以直接IIS上面发布. 二.库文件自动生成的类 接口类 usi ...
- docker(4)使用Dockerfile文件创建镜像-对docker(3)的改进
在<docker(3)docker下的centos7下安装jdk>中,当进入容器后,执行 java命令 不能运行,需要执行source /etc/profile才能执行.如果采用Docke ...