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("爺,現在是年輕人的時代,您就暫且休息去吧~~"); } })();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM