JavaScript & HTML - Stop Background Sound after Video Screen is Exit

前端 未结 2 817
梦如初夏
梦如初夏 2021-01-27 07:10

I want to stop the video from playing the video background sound or stop the sounds it AFTER I exit the video screen.

Full screen

The bug right now is t

2条回答
  •  佛祖请我去吃肉
    2021-01-27 08:02

    This worked for me

                document.addEventListener('fullscreenchange', exitHandler);
                document.addEventListener('webkitfullscreenchange', exitHandler);
                document.addEventListener('mozfullscreenchange', exitHandler);
                document.addEventListener('MSFullscreenChange', exitHandler);
    
                function exitHandler() {
                    if (!document.fullscreenElement && !document.webkitIsFullScreen && !document.mozFullScreen && !document.msFullscreenElement) {
                        video.pause();
                    }
                } 
    

提交回复
热议问题