zoukankan      html  css  js  c++  java
  • 自定义滑块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 = '' + 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 = '' + 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 = '' + this.currentTime / this.alltime * 213 + 'px'
          }
        },
        touchend () {
          this.statu = false
        }
      }
    

      

  • 相关阅读:
    java javax.annotation.Resource注解的详解
    Struts2注解详解
    HDU 5074-Hatsune Miku(DP)
    Mac下配置Cocos2d-x3.1环境
    POJ 2109 Power of Cryptography
    Swift编程语言学习10—— 枚举属性监视器
    解决:Determining IP Information for eth0 一直停留 无法进入系统
    Bootstrap之表格
    创建和关联内容数据库到指定Web应用程序和站点集
    Ucan23操作系统项目地址
  • 原文地址:https://www.cnblogs.com/yiyi17/p/8967095.html
Copyright © 2011-2022 走看看