_vue时间轴 视频拖动条">
当前位置:   article > 正文

vue 模拟视频进度条组件(可支持点击,拖拽)_vue时间轴 视频拖动条

vue时间轴 视频拖动条

videoProgress.vue

<template>
    <div
        ref="progressWrapper"
        class="video-progress"
        @click="onTrackClick"
        @mousemove="mouseMove">
        <div class="video-progress-track" :style="{ 'width': progress + '%'}"></div>
        <div class="video-progress-point" ref="slider" :style="{ 'left': progress + '%'}" @mousedown="mouseDown"></div>
    </div>
</template>
<script>
export default {
    props: {
        progress: {
            type: Number,
            default: 0
        }
    },
    data() {
        return {
            isDrag: false,
            distanceX: 0,
            videoProgress: 0
        }
    },
    watch: {
        isDrag(val) {
            this.$emit('getDragStatus', val)
        },
        progress(val) {
            if (this.$refs.progressWrapper) {
                this.videoProgress = (this.progress * (this.$refs.progressWrapper.offsetWidth * this.zoom)) / 100
            }
        }
    },
    methods: {
        onTrackClick(event) {
            this.isDrag = false
            const sliderElement = this.$refs.slider
            if (event.target === sliderElement) return
            this.calculateDiatance(event.offsetX)
        },
        mouseDown(event) {
            if (this.progress === 100) return
            this.isDrag = true
            this.distanceX = event.pageX - this.videoProgress
            document.addEventListener('mouseup', () => {
                this.isDrag = false
            })
        },
        mouseMove(event) {
            if (this.isDrag) {
                const offsetX = event.pageX - this.distanceX
                this.calculateDiatance(offsetX)
            }
        },
        calculateDiatance(pageX) {
            const parentWidth = this.$refs.progressWrapper.offsetWidth
            const sliderWidth = this.$refs.slider.offsetWidth
            if (pageX > parentWidth - sliderWidth) {
     
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/130230
推荐阅读
相关标签