我的网站在轮播中播放了多个 youtube 视频。当用户点击 youtube 视频时,我想停止轮播的自动滚动。这是我正在编写的代码,它向我抛出“players[player_id].getPlayerState() 不是函数”错误。
youtube 库也从第三方 javascript 加载到我的网站中。
玩家 = {};
window.onYouTubeIframeAPIReady = function(){
$('.youtube-video iframe').each(function() {
players[$(this).attr('id')] = new YT.Player($(this).attr('id'), {
events: {
'onStateChange': onPlayerStateChange($(this).attr('id'))
}
});
});
}
function onPlayerStateChange(player_id){
return function(event) {
if(players[player_id].getPlayerState() == 3 ||players[player_id].getPlayerState() == 1) {
//stop the auto scrolling
}
if(players[player_id].getPlayerState() == 0 || players[player_id].getPlayerState() == 2) {
//start auto scrolling.
}
}
}
如果您能在我的代码中找到问题,请告诉我。提前致谢!