码迷,mamicode.com
首页 > Windows程序 > 详细

HTML5 full-screen全屏API

时间:2017-06-16 16:42:02      阅读:303      评论:0      收藏:0      [点我收藏+]

标签:poi   cti   UI   .com   and   opera   text   pre   显示   

这篇文章纯属记录,非常感谢张鑫旭大神的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("爷,现在是年轻人的时代,您就暂且休息去吧~~");
    }
})();

 

HTML5 full-screen全屏API

标签:poi   cti   UI   .com   and   opera   text   pre   显示   

原文地址:http://www.cnblogs.com/coolle/p/7027578.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!