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("点击", "点击退出"); } }

转载于:https://www.cnblogs.com/coolle/p/7027578.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值