Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript youtube视频暂停时触发事件_Javascript_Youtube_Youtube Javascript Api - Fatal编程技术网

Javascript youtube视频暂停时触发事件

Javascript youtube视频暂停时触发事件,javascript,youtube,youtube-javascript-api,Javascript,Youtube,Youtube Javascript Api,我在YT视频上加了文字 到目前为止,我正在使用event.data==YT.PlayerState.PLAYING来触发一个事件,以便在视频启动时隐藏一个div,但我还想做的是在视频暂停时再次显示它: 到目前为止,我所拥有的: var player; function onYouTubeIframeAPIReady() { player = new YT.Player('ytplayer', { //height: '600', // width: '1

我在YT视频上加了文字

到目前为止,我正在使用
event.data==YT.PlayerState.PLAYING
来触发一个事件,以便在视频启动时隐藏一个div,但我还想做的是在视频暂停时再次显示它:

到目前为止,我所拥有的:

var player;

function onYouTubeIframeAPIReady() {
    player = new YT.Player('ytplayer', {
        //height: '600',
        // width: '100%',
        videoId: 'lnzoWFylJ0k',
        events: {

            'onStateChange': function(event) {
                if (event.data == YT.PlayerState.PLAYING) {
                    hideIt();
                }

            }

        }
    });
}

function hideIt() {
    console.log("something happened");

    if (window.matchMedia("(min-width: 767px)").matches) {

        $("h1.txt--white").hide();

    }

提前谢谢

有一个onStateChange事件监听器(您正在使用),然后可以挂接到“暂停”状态更改

您已经在使用播放事件,使用
YT.PlayerState.PAUSED
是否存在问题


这似乎是合乎逻辑的答案,请更新事件处理程序以检查是否暂停并显示它。执行此操作:不起作用:-我要做的是使两个事件都“onStateChange”起作用:函数(事件){if(event.data==YT.PlayerState.PLAYING){hideIt();}if(event.data==YT.PlayerState.PAUSED){showIt();}namretiolnave“不起作用”,如“什么都没发生”?你试过调试它吗,看看你的showIt方法是否有效?最简单的方法是添加一些打印语句,哈哈。可能会发布你完整的更新代码?你也有一个拼写错误,可能会检查你的代码是否有相同的拼写错误。(暂停而不是编成)不起作用-我的函数被遗漏了,名为抱歉和谢谢!