zoukankan      html  css  js  c++  java
  • HTML5 full-screen全屏API

    这篇文章纯属记录,非常感谢张鑫旭大神的demo

    原文地址: http://www.zhangxinxu.com/study/201210/html5-full-screen-api.html

    代码

    CSS代码:
    .full {
        text-align: center;
        cursor: pointer;
    }
    
    .full img {
        vertical-align: middle;
    }
    
    .full:hover img {
        box-shadow: 2px 2px 4px rgba(0,0,0,.45);
    }
    
    .full:after {
        /* 图片垂直居中显示 */
        display: inline-block;
        content: '';
        width: 0;
        height: 100%;
        vertical-align: middle;
    }
    
    :-webkit-full-screen img    { height: 60%; }
    :-moz-full-screen img       { height: 60%; }
    :-ms-full-screen img        { height: 60%; }
    :-o-full-screen img         { height: 60%; }
    :full-screen img            { height: 60%; }
    HTML代码:
    <div class="full" title="点击全屏浏览"><img src="http://image.zhangxinxu.com/image/study/s/s512/mm1.jpg" /></div>
    JS代码:
    (function() {
        var runPrefixMethod = function(element, method) {
            var usablePrefixMethod;
            ["webkit", "moz", "ms", "o", ""].forEach(function(prefix) {
                if (usablePrefixMethod) return;
                if (prefix === "") {
                    // 无前缀,方法首字母小写
                    method = method.slice(0,1).toLowerCase() + method.slice(1);
                    
                }
                
                var typePrefixMethod = typeof element[prefix + method];
                
                if (typePrefixMethod + "" !== "undefined") {
                    if (typePrefixMethod === "function") {
                        usablePrefixMethod = element[prefix + method]();
                    } else {
                        usablePrefixMethod = element[prefix + method];
                    }
                }
            });
            
            return usablePrefixMethod;
        };
        
        if (typeof window.screenX === "number") {
            var eleFull = document.querySelector(".full");
            eleFull.addEventListener("click", function() {
                if (runPrefixMethod(document, "FullScreen") || runPrefixMethod(document, "IsFullScreen")) {
                    runPrefixMethod(document, "CancelFullScreen");
                    this.title = this.title.replace("退出", "");
                } else if (runPrefixMethod(this, "RequestFullScreen")) {
                    this.title = this.title.replace("点击", "点击退出");
                }
            });
        } else {
            alert("爷,现在是年轻人的时代,您就暂且休息去吧~~");
        }
    })();
  • 相关阅读:
    Comet OJ
    Comet OJ
    Comet OJ
    Comet OJ
    Codeforces Round #562 (Div. 2)
    P1202 USACO1.1 黑色星期五
    P1201 USACO1.1 贪婪的送礼者
    【线段树】HDU1166:敌兵布阵
    标准C++中的string类的用法总结(转)
    【递归】分形
  • 原文地址:https://www.cnblogs.com/coolle/p/7027578.html
Copyright © 2011-2022 走看看