在Mac OS X上的html页面全屏显示

时间:2014-06-17 14:59:41

标签: html css macos

我正在努力实现本网站的这一功能:

http://flatfull.com/themes/note/index.html

如果你单击左上角的笔记本电脑徽标,你可以看到在Mac OS X上的Safari(我只测试过它)上自动将页面全屏显示,我怎么能实现这个功能?

1 个答案:

答案 0 :(得分:0)

这将帮助您(将其命名为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 );