【发布时间】:2014-09-29 18:55:05
【问题描述】:
我正在创建一个函数,当用户将鼠标悬停在 div 上时插入 YouTube iframe,然后 when the user leaves div the video is paused. Everythings 工作正常,但当用户离开 div 时视频不会暂停。
小提琴:http://jsfiddle.net/508oknm7/20/
有什么想法吗?谢谢!
var tag = document.createElement('script'),
firstScriptTag = document.getElementsByTagName('script')[0];
tag.src = "https://www.youtube.com/player_api";
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
$(".video_wrap").on({
mouseenter: function () {
player = new YT.Player($(this).attr('id'), {
height: '240',
width: '320',
videoId: 'wJnnT1SGEsc',
playerVars: {
wmode: "transparent",
controls: 0,
showinfo: 0,
rel: 0,
modestbranding: 1,
iv_load_policy: 3 //anottations
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
function onPlayerReady(event) {
event.target.playVideo();
}
},
mouseleave: function () {
player.pauseVideo();
}
});
【问题讨论】:
标签: javascript jquery youtube-api