HTML5代码实例:HTML5全屏API

 

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}

....................................................................

.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.οnlοad=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直接运行即可。。。


具体请点击:http://www.verydemo.com/demo_c101_i53566.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值