自定义滑块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 ...
随机推荐
- nginx limit_req限速设置
WIKI: http://wiki.nginx.org/HttpLimitReqModule 漏桶原理(leaky bucket): http://en.wikipedia.org/wiki/Leak ...
- 改变iOS app的icon(iOS10.3)
原文 改变iOS app的icon官方iOS10.3新增了可以让开发者去更改app的icon,接下来看看怎么更改.官方API给的东西很少,只是介绍了一个实例方法: 1 open func setAlt ...
- c#随笔-正则
- P3970 [TJOI2014]上升子序列
传送门 DP 十分显然的DP,但是不好写 设 f[ i ] 表示以第 i 个数作结尾时的方案数,原序列为 a 如果不考虑相同的序列: 那么转移就是 Σ f[ j ] (0< j < i & ...
- hdu6438 Buy and Resell 买卖物品 ccpc网络赛 贪心
题目传送门 题目描述: 有n座城市,每座城市都可以对一个物品进行一次的买进或者卖出,可以同时拥有多个物品,计算利润最大值,并且交易次数要最少.(买入卖出算两次操作) 思路: 建立两个小根堆 优先队列, ...
- poj3274 找平衡数列(哈希加一点数学思维)
题目传送门 题目大意:有n只牛,每只牛有k个属性,接下来n个数字,每个数字的二进制位上的1和0分别表示某种属性的有或者无,然后一个特殊数列就是,一个区间内所有牛的各种属性的总和相等(有e种1属性 e ...
- 07-图5 Saving James Bond - Hard Version (30 分)
This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...
- day26 网络通讯的整个流程
一.网络通信原理 1. 互联网的本质就是一系列的网络协议 2. 互联网协议按照功能不同分为osi七层或tcp/ip五层或tcp/ip四层 各层的功能简述: [1]物理层:主要定义物理设备标准,如网 ...
- yum安装zabbix故障报错
装zabbix时报错 [root@zabbix ~]# rpm -ivh zabbix-server-mysql-2.2.3-1.el6.x86_64.rpm zabbix-web-mysql-2.2 ...
- 增加tomcat多实例
第一步:解压 第二步:修改端口 /data/service/tomcat1/conf <Server port="8006" shutdown="SHUTDOWN& ...