jQuery: How to execute code when exiting fullscreen mode with escape button?

半世苍凉 提交于 2019-12-05 10:30:53

Depending on which browser you are using you will need to bind the appropriate prefix. You can detect the event screenchange and if it has changed you need to poll whether it is currently in fullscreen or not. The fullscreen property is always bound to the document so that is what you can use to check the current state and use it to fire the events accordingly. The following snippet binds to all major browser and detects in all major browsers. Note: these events are not available in ios

$(el).bind('webkitfullscreenchange mozfullscreenchange fullscreenchange', function(e) {
    var state = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
    var event = state ? 'FullscreenOn' : 'FullscreenOff';

    // Now do something interesting
    alert('Event: ' + event);    
});

Further reading on this http://davidwalsh.name/fullscreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!