账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    播放视频时不管鼠标在哪里都会暂停轮播,点击播放怎么取消@mouseleave事件?
    48
    0

    <template>
    <div>

    <div id="sidebar">
      <div class='panel'>
        <div id="slider">  
          <div class="window" @mouseover="stop" @mouseleave="player">
            <!-- 轮播图片 -->
            <ul class="container" :style="containerStyle">
              <li @click="dianji(sliders[sliders.length - 1].a)">        
                <img :src="sliders[sliders.length - 1].img" alt="">              
              </li>
              <li v-for="(item, index) in sliders" :key="index">
                <video v-if="item.type == 'video_pro'" id="myVideo" class="video-js vjs-big-play-centered" 
                  controls data-setup="{}">
                  <source :src="item.video" type='video/mp4'>
                </video>
                <img class="img" v-else="item.type == 'image'" @click="dianji(item.a)" :src="item.img" alt="">             
              </li>
    
              <li @click="dianji(sliders[0].a)">
                <img :src="sliders[0].img" alt="">         
              </li>
    
            </ul>
    
            <!-- 轮播左右箭头 -->
            <ul class="direction">
              <li class="left" @click="move(450, 1, speed)">
                <svg class="icon" width="18px" height="18px" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path fill="#ffffff" d="M481.233 904c8.189 0 16.379-3.124 22.628-9.372 12.496-12.497 12.496-32.759 0-45.256L166.488 512l337.373-337.373c12.496-12.497 12.496-32.758 0-45.255-12.498-12.497-32.758-12.497-45.256 0l-360 360c-12.496 12.497-12.496 32.758 0 45.255l360 360c6.249 6.249 14.439 9.373 22.628 9.373z"  /></svg>
              </li>
              <li class="right" @click="move(450, -1, speed)">
                <svg class="icon" width="18px" height="18px" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path fill="#ffffff" d="M557.179 904c-8.189 0-16.379-3.124-22.628-9.372-12.496-12.497-12.496-32.759 0-45.256L871.924 512 534.551 174.627c-12.496-12.497-12.496-32.758 0-45.255 12.498-12.497 32.758-12.497 45.256 0l360 360c12.496 12.497 12.496 32.758 0 45.255l-360 360c-6.249 6.249-14.439 9.373-22.628 9.373z"  /></svg>
              </li>
            </ul>
            <!-- 轮播圆点 -->
            <ul class="dots">
              <li v-for="(dot, i) in sliders" :key="i" 
                :class="{dotted: i === (currentIndex-1)}" @click = jump(i+1)>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>    

    </div>
    </template>
    <script>

    import Video from 'video.js'
    import { debug } from 'util'
    export default {

    name: 'Rotation_chart',
    props: {
      initialSpeed: {
        type: Number,
        default: 30
      },
      initialInterval: {
        type: Number,
        default: 4
      }
    },
    data () {
      return {
        sliders:[
          { 
            type: 'video_pro',         
            video: 'https://mooc.lenovo.com/wp-content/uploads/2018/11/20181128.mp4',
          },
          {   
            type: 'image',    
            img: require('../public/images/acronym.jpg'),
            a: 'sip:selfservice@lenovo.com'           
          },
          {
            type: 'image',
            img: require('../public/images/studio.jpg'),
            a: 'http://ccai.xyz'
          },
          {
            type: 'image',
            img: require('../public/images/baibianxiaoka.png'),
            a: 'http://ss.lenovo.com'
          },
          //  { 
          //   type: 'video_pro',         
          //   video: 'https://mooc.lenovo.com/wp-content/uploads/2018/11/助小咖宣传最终版20181128.mp4',
          // },
        ],
        currentIndex:1,
        distance:-450,
        transitionEnd: true,
        speed: this.initialSpeed
      }
    },
    computed:{
      containerStyle() {
        return {
          transform:`translate3d(${this.distance}px, 0, 0)`
        }
      },
      interval() {
        return this.initialInterval * 1500
      },
    },
    mounted() {
      this.init();
      this.initVideo()
    },
    methods:{
      init() {
        this.player()
        window.onblur = function() { this.stop() }.bind(this)
        window.onfocus = function() { this.player() }.bind(this)
      },
      move(offset, direction, speed) {
        console.log(speed)
        if (!this.transitionEnd) return
        this.transitionEnd = false
        direction === -1 ? this.currentIndex += offset/450 : this.currentIndex -= offset/450
        if (this.currentIndex > 4) this.currentIndex = 1
        if (this.currentIndex < 1) this.currentIndex = 4
    
        const destination = this.distance + offset * direction
        this.animate(destination, direction, speed)
      },
      animate(des, direc, speed) {
        if (this.temp) {
          window.clearInterval(this.temp);
          this.temp = null ;
        }
        this.temp = window.setInterval(() => {
          if ((direc === -1 && des < this.distance) || (direc === 1 && des > this.distance)) {
            this.distance += speed * direc
          } else {
            this.transitionEnd = true
            window.clearInterval(this.temp)
            this.distance = des
            if (des < -1820) this.distance = -450
            if (des > -450) this.distance = -1820
          }
        }, 50)
      },
      jump(index) {
        const direction = index - this.currentIndex >= 0 ? -1 : 1;
        const offset = Math.abs(index - this.currentIndex) * 450;
        const jumpSpeed = Math.abs(index - this.currentIndex) === 0 ? this.speed : Math.abs(index - this.currentIndex) * this.speed ;
        this.move(offset, direction, jumpSpeed)
      },
      
      player() {     
        if (this.timer) {
          window.clearInterval(this.timer)
          this.timer = null
        }      
        this.timer = window.setInterval(() => {       
          this.move(450, -1, this.speed)
        }, this.interval)
      },
      stop() {
        window.clearInterval(this.timer)
        this.timer = null
      },
      dianji(a){
        window.open(a)
      },
      initVideo() {
        let _index = 0;
        let timer = null;
        let flag = true;
        $(".window").hover(hoverIn,hoverOut)
    
        function hoverIn() {
          console.log('timer in',timer)
          clearInterval(timer);
          flag = false;
        }
        function hoverOut() {
          console.log('timer',timer)
          flag = true;
          clearInterval(timer);
          timer = setInterval(go, 4000);
        }
    
        let leftArrow = $(".left");  //轮播图左箭头
        let rightArrow = $(".right");//轮播图右箭头
        let dots = $(".dots");       //轮播图四个点点
        let spanGroup = $(".vjs-big-play-button span");  //点击播放 
        //  debugger
        let player = this.player()
        let myPlayer1 = Video('myVideo')
        myPlayer1.on('play',() =>{
          clearInterval(null);
          console.log('正在播放');            
          leftArrow.hide()
          rightArrow.hide()
          dots.hide()
          spanGroup.hide()
          // debugger
          // that.player(null) 
          // debugger 
          $(".window").unbind('mouseover').unbind('mouseleave')  
        }); 
        //暂停--播放完毕后也会暂停
        myPlayer1.on('pause',() =>{
          console.log("暂停中")
          leftArrow.show()
          rightArrow.show()
          dots.show()
          spanGroup.show()
          //  $(".window").hover(hoverIn,hoverOut)
        }); 
        // 结束
        myPlayer1.on('ended',() => {
          console.log('结束');
          leftArrow.show()
          rightArrow.show()
          dots.show()
          spanGroup.show()
        })
      }
    }

    }
    </script>

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    • 为你卑微了我自己 普通会员 1楼

      在JavaScript中,你可以使用mouseover事件来监听鼠标在视频中的位置,然后使用mouseout事件来取消监听。以下是一个简单的示例:

      ```javascript var video = document.getElementById('videoId');

      video.addEventListener('mouseover', function(event) { if (event.target.id === 'player') { video.pause(); } });

      video.addEventListener('mouseout', function(event) { if (event.target.id === 'player') { video.play(); } }); ```

      在这个示例中,我们首先获取了视频元素,然后为它添加了mouseovermouseout事件监听器。当鼠标在视频中的位置触发mouseover事件时,我们检查事件的目标是否是视频元素。如果是,我们就暂停视频播放;如果不是,我们就恢复视频播放。

      注意,我们还需要为视频元素添加一个唯一的ID,以便我们可以正确地识别视频元素。

      另外,你还需要确保在视频播放时,鼠标不再悬停在视频上。你可以在mouseout事件处理函数中添加代码来实现这一点。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部