如何解决为什么回调函数没有启动?
我不知道为什么,但 YouTube API 不起作用,我完全按照说明进行了操作。但是播放器 div 是空的。看起来回调函数没有启动。因为 console.log(YT) 未定义
哈巴狗
.main-house__main
.video-block
.video
div( id="player")
.video__preview
img(src="img/images/preview.jpg")
.video__button-wrapper
button(id="video-button").video__button
js
export default () => {
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag,firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
console.log('api')
player = new YT.Player('player',{
height: '360',width: '640',videoId: 'M7lc1UVf-VE',events: {
'onReady': onPlayerReady,}
});
}
function onPlayerReady(event) {
var playButton = document.getElementById("video-button");
if(!playButton) {
return null
}
playButton.addEventListener("click",function () {
player.playVideo();
});
}
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。