当youtube视频播放在网页中结束时,有没有办法向下滑动到div??
答案 0 :(得分:1)
您可以通过订阅您感兴趣的活动来使用Youtube Api。
例如,以这种方式:
<div id="player"></div>
<script src="http://www.youtube.com/player_api"></script>
<script>
// create youtube player
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: '0Bmhjf0rKe8',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// autoplay video
function onPlayerReady(event) {
event.target.playVideo();
}
// when video ends
function onPlayerStateChange(event) {
if(event.data === 0) {
$('html, body').animate({
scrollTop: $("#elementtoScrollToID").offset().top
}, 2000);
}
}
</script>
<div id='elementtoScrollToID' class='my_div'> Hello! </div>