悬停播放youtube视频 [英] Play youtube video on hover

查看:235
本文介绍了悬停播放youtube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要在悬停时播放youtube视频

I just need to play the youtube video only when hovered

我在这里摆弄着小提琴,无法正常工作.

I have here a fiddle and can't get it to work.

$(document).ready(function(){
  $(function() {

      var playersrc = jQuery(iframe).attr('src');

          $('div').hover(function(){
          $('iframe').attr('src',playersrc+'&autoplay=1');
      }, function(){
          $('iframe').attr('src',playersrc);
      });
  });       
});

https://jsfiddle.net/rhr5p0pg/2/

更新的提琴: https://jsfiddle.net/rhr5p0pg/4/

现在它可以播放所有内容,并且当鼠标离开时它不会返回其原始视频

now it plays all and when your mouse leaves the it does not go back to its originial video

推荐答案

您仅存储第一个视频uri(src).

You store just the first video uri (src).

这样的事情

$(document).ready(function(){
  var nowPlaying = "none";
      $('div').hover(function(){
          nowPlaying = $(this).find('iframe').attr('src');
          $(this).find('iframe').attr('src',nowPlaying+'&autoplay=1');
      }, function(){
          $(this).find('iframe').attr('src',nowPlaying);
      });
});

https://jsfiddle.net/rhr5p0pg/5/

这篇关于悬停播放youtube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆