自定义滑块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 ...
随机推荐
- P3750 [六省联考2017]分手是祝愿 期望DP
\(\color{#0066ff}{ 题目描述 }\) Zeit und Raum trennen dich und mich. 时空将你我分开. B 君在玩一个游戏,这个游戏由 \(n\) 个灯和 ...
- Boost lockfree deque 生产者与消费者多对多线程应用
boost库中有一个boost::lockfree::queue类型的 队列,对于一般的需要队列的程序,其效率都算不错的了,下面使用一个用例来说明. 程序是一个典型的生产者与消费者的关系,都可以使用多 ...
- 数据结构19: BF算法(普通模式匹配算法)
判断两个串之间是否存在主串与子串的关系,这个过程称为串的模式匹配. 在串的模式匹配过程,子串 T 通常被叫做“模式串”. 普通的模式匹配(“BF”算法) 判断两个串是否存在子串与主串的关系,最直接的算 ...
- servlet验证2
登录界面 登录成功后 数据库 地址:https://gitee.com/lgcj1218/j2eehomework/tree/master
- swift -- 单例+ lazy懒加载 + 第三方库
//工具类单例 static let goods : NHGoods = { let good = NHGoods() return good }() //懒加载 lazy var registerB ...
- 解决SMON_SCN_TO_TIME_AUX表损坏故障
同事在给客户做数据库巡检的过程中,发现其中一个数据库的alert日志中报了一个坏块的错误信息,具体如下: Reading datafile '+DATA_DW/xtdw/datafile/sysaux ...
- laytpl....
switch 语句.. <ul class='mui-table-view'> <!--switch 语句 ...--> {{# switch(d['event']){ cas ...
- Number Sequence (KMP第一次出现位置)
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...
- HDU-Digital Roots(思维+大数字符串模拟)
The digital root of a positive integer is found by summing the digits of the integer. If the resulti ...
- nginx配置应用
启动nginxvim /usr/local/lnmp/nginx/conf/nginx.conf mkdir /wwwcd /wwwvim index.html www.westos.orgmkdir ...