This question already has answers here:
onclick go full screen
(8个答案)
5年前关闭。
我正在尝试实现此网站的此功能:
http://flatfull.com/themes/note/index.html
如果单击左上角的笔记本徽标,您会看到在Mac OS X上的Safari(我仅对其进行过测试)上,该页面会自动全屏显示,我如何实现此功能?
(8个答案)
5年前关闭。
我正在尝试实现此网站的此功能:
http://flatfull.com/themes/note/index.html
如果单击左上角的笔记本徽标,您会看到在Mac OS X上的Safari(我仅对其进行过测试)上,该页面会自动全屏显示,我如何实现此功能?
最佳答案
这将帮助您(将其命名为fs.js)并:
/*global Element */
(function( window, document ) {
'use strict';
var keyboardAllowed = typeof Element !== 'undefined' && 'ALLOW_KEYBOARD_INPUT' in Element, // IE6 throws without typeof check
fn = (function() {
var fnMap = [
[
'requestFullscreen',
'exitFullscreen',
'fullscreenchange',
'fullscreen',
'fullscreenElement',
'fullscreenerror'
],
[
'webkitRequestFullScreen',
'webkitCancelFullScreen',
'webkitfullscreenchange',
'webkitIsFullScreen',
'webkitCurrentFullScreenElement',
'webkitfullscreenerror'
],
[
'mozRequestFullScreen',
'mozCancelFullScreen',
'mozfullscreenchange',
'mozFullScreen',
'mozFullScreenElement',
'mozfullscreenerror'
]
],
i = 0,
l = fnMap.length,
ret = {},
val,
valLength;
for ( ; i < l; i++ ) {
val = fnMap[ i ];
if ( val && val[1] in document ) {
for ( i = 0, valLength = val.length; i < valLength; i++ ) {
ret[ fnMap[0][ i ] ] = val[ i ];
}
return ret;
}
}
return false;
})(),
screenfull = {
isFullscreen: document[ fn.fullscreen ],
element: document[ fn.fullscreenElement ],
request: function( elem ) {
var request = fn.requestFullscreen;
elem = elem || document.documentElement;
// Work around Safari 5.1 bug: reports support for
// keyboard in fullscreen even though it doesn't.
// Browser sniffing, since the alternative with
// setTimeout is even worse
if ( /5\.1[\.\d]* Safari/.test( navigator.userAgent ) ) {
elem[ request ]();
} else {
elem[ request ]( keyboardAllowed && Element.ALLOW_KEYBOARD_INPUT );
}
},
exit: function() {
document[ fn.exitFullscreen ]();
},
toggle: function( elem ) {
if ( this.isFullscreen ) {
this.exit();
} else {
this.request( elem );
}
},
onchange: function() {},
onerror: function() {}
};
if ( !fn ) {
window.screenfull = null;
return;
}
document.addEventListener( fn.fullscreenchange, function( e ) {
screenfull.isFullscreen = document[ fn.fullscreen ];
screenfull.element = document[ fn.fullscreenElement ];
screenfull.onchange.call( screenfull, e );
});
document.addEventListener( fn.fullscreenerror, function( e ) {
screenfull.onerror.call( screenfull, e );
});
window.screenfull = screenfull;
})( window, document );
08-25 13:30