点击这里给我发消息 点击这里给我发消息
首页 > 行业资讯 > HTML>详细内容

HTML5代码实例:HTML5全屏API

添加时间:2013-12-6
    相关阅读: HTML


HTML5全屏API ,全屏浏览图片。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
 

<title>html5 -fullscreen-api</title>
 
<style>
 

*{ margin:0; padding:0}
 
img{ display:block; margin:0 auto}
 
.imgContainer:-webkit-full-screen {
width:100%; height:100%; background:#060; overflow:hidden; background:#000; text-align:center;
 
position:fixed;
 
left:0; top:0;
 
display:table-cell;
 
bottom:0; right:0;
 

 

.imgContainer:-moz-full-screen  {
width:100%; height:100%; background:#060;overflow:hidden; background:#000; text-align:center;
 
position:fixed;
 
left:0; top:0;
 
bottom:0; right:0;
 
display:table-cell;
 
vertical-align:middle
 

 
.imgContainer:-webkit-full-screen  img{ max-width:100%;  display:inline-block; vertical-align:middle ;cursor:url("http://a.xnimg.cn/n/apps/photo/modules/photo-view/cssimg/zoomOut.cur"), auto;
}
.imgContainer:-moz-full-screen  img{ max-width:100%; display:inline-block; vertical-align:middle;cursor:url("http://a.xnimg.cn/n/apps/photo/modules/photo-view/cssimg/zoomOut.cur"), auto;
  } 
 


</style>
 

 


<script type="text/javascript">
 

 

(function(){
 
           var fullScreenApi={
 
          
 
             supportsFullScren:false,
 
                 isFullScreen: function() { return false; },
                 requestFullScreen: function() {},
                 cancelFullScreen: function() {},
 
                 prefix:''
 
                     
           }
 
   browserPrefixes = 'webkit moz o ms khtml'.split(' ');
 
 
   if(typeof document.cancelFullScreen!='undefined'){
 
           fullScreenApi.supportsFullScren=true
 
          
 
           }
 
           else{
 
                   for (var i = 0, il = browserPrefixes.length; i < il; i++ ) {
 
                        fullScreenApi.prefix = browserPrefixes[i];
 
                        if (typeof document[fullScreenApi.prefix + 'CancelFullScreen' ] != 'undefined' ) {
 
                                fullScreenApi.supportsFullScreen = true;
 
                                break;
 
                        }
 
                   }
 
                   }
 
                  
                //如果浏览支持全屏  
 
      if(fullScreenApi.supportsFullScreen){
 
                fullScreenApi.fullScreenEventName = fullScreenApi.prefix + 'fullscreenchange'; 
 
                  fullScreenApi.isFullScreen=function(){
 
                         
 
                          switch (this.prefix){
 
                                 
                                  case '':
 
                                  return document.fullScreen
 
                                  case 'webkit':
 
                                  return document.webkitIsFullScreen
 
                                  default:
 
                                  return document[this.prefix+'FullScreen']
 
                                 
                                  }
 
                         
 
                         
 
                          }
 
 
                  fullScreenApi.requestFullScreen=function(el){
 
                        return (this.prefix === '') ? el.requestFullScreen() : el[this.prefix + 'RequestFullScreen']();                         
 
                         
 
                          }
 
                   fullScreenApi.cancelFullScreen=function(el){
 
                        return (this.prefix === '') ? el.cancelFullScreen() : el[this.prefix + 'CancelFullScreen']();                         
 
                         
 
                          }
  
                  }
 
        window.fullScreenApi = fullScreenApi;       
 
        })()
 

</script>

</head>

<body>
 
<h1 align="center"></h1>
 
<div class="imgContainer">
 
<a href="javascript:void(0)"><img src="http://image.dili360.com/photo/hdtj/2012/1205/62_15141524412_20121205094753.jpg"></a></div>
 
<div class="imgContainer">
 
<a href="javascript:void(0)"><img src="http://image.dili360.com/photo/hdtj/2012/1205/62_15141524424_20121205094753.jpg"></a></div>
 
<script type="text/javascript">
 

window.onload=function(){
  
        if (window.fullScreenApi.supportsFullScreen) {               
        var imgContainer=document.getElementsByTagName('div');
 
        var imgsLen=imgContainer.length;
 
        for(var i=0; i<imgsLen;i++){
 
                imgContainer[i].addEventListener('click',function(){
 
                       
 
                       
 
                                if (!fullScreenApi.isFullScreen()) {
 
            this.style.lineHeight=window.screen.height+'px';
 
                        window.fullScreenApi.requestFullScreen(this)               
                        }
 
                         else {
 
                        window.fullScreenApi.cancelFullScreen(document)               
                }                       
 
                },true)
 
        }
 
        }
 

       
 
       
 
}
 

</script>
 


</body>
 

</html>

用chrome或者firefox直接运行即可。。。



咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册