我想在" onStateChange"时改变YouTube视频宽度。事件在1(播放)时触发,然后在0(结束)和2(暂停)时恢复到原始大小。
我是JavaScript和jQuery的新手。但是,我们说我有这个
<section><iframe id="player" src="https://www.youtube.com/embed/DjB1OvEYMhY?enablejsapi=1"></iframe></section>
<script>
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player( 'player', {
events: { 'onStateChange': onPlayerStateChange }
});
}
</script>
<script src="https://www.youtube.com/iframe_api"></script>
为什么这个jquery不起作用?
jQuery(document).ready(function($) {
YT.PlayerState.ENDED = function(e) {
$('section iframe').animate({ width: "50%"}, 'slow')};
YT.PlayerState.PAUSED = function(e) {
$('section iframe').animate({ width: "50%"}, 'slow')};
YT.PlayerState.PLAYING = function(e) {
$('section iframe').animate({ width: "100%" }, 'slow');
}
我获得的API信息来自https://developers.google.com/youtube/iframe_api_reference#Events