我试图用Youtube播放器进行控制,这里有几个按钮,这些按钮有不同的时间(秒),可以修改播放器的时间。我遇到了函数seekTo的问题,当我点击" test"按钮,这一个将屏幕移到顶部。你能帮助我吗?
谢谢!
<div id="ytplayer"></div>
<script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
var sec = 12;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
playerVars: { 'autoplay': 0, 'controls': 0 },
videoId: "a5vTA4L_PB4"
});
}
$(window).load(function(){
jQuery('#test').click(function(){
console.log(player);
player.seekTo(sec);
return false;
});
});
</script>
</div>
<a href="#" id="test">Test</a>