zoukankan      html  css  js  c++  java
  • 浏览器常用高宽的JQ插件

    View Code
    /**
     * 兼容BackCompat,CSS1Compat两模式渲染的页面,测试的浏览器 :friefox ie678 chrome opera 
     * @author Lonely 
     
    */
    (function($) {
        
    /**
         * 取得浏览器视图的宽度
         
    */
        $.viewWidth
    =function(){
              
    var w = 0, D=document;
              
    if( D.documentElement &&  D.documentElement.clientWidth ) {
                  w  
    = D.documentElement.clientWidth;
              } 
    else if( D.body &&  D.body.clientWidth ) {
                  w  
    = D.body.clientWidth;
              }
              
    return w ;
        }
        
    /**
         * 取得浏览器视图的高度
         
    */
        $.viewHeight
    =function(){
              
    var h = 0, D=document;
              
    if(document.compatMode!='CSS1Compat'){
                   h 
    = D.body.clientHeight;
              }
    else{
                   
    if( D.documentElement &&  D.documentElement.clientHeight ) {
                    h 
    = D.documentElement.clientHeight;
                  } 
    else if( D.body &&  D.body.clientHeight ) {
                    h 
    = D.body.clientHeight;
                  }
              }
              
    return h;
        }
        
    /**
         * 取得画板的高度(即所有内容,当浏览器内容不足的时候为浏览器视图大小)
         
    */
        $.canvasHeight
    =function(){
            
    var D=document,h=0;
            h
    =Math.max(Math.max(D.body.scrollHeight,D.documentElement.scrollHeight),
                Math.max(D.body.offsetHeight,D.documentElement.offsetHeight),
                Math.max(D.body.clientHeight,D.documentElement.clientHeight)
            );
            
    if($.browser.msie&&$.browser.version>6&&D.body.scrollHeight<$.viewHeight()){
                h
    =D.body.clientHeight;
            }
            
    if($.browser.msie&&document.compatMode=='CSS1Compat'&&D.body.scrollHeight<$.viewHeight()){
                
    if($.browser.version>7&&$.browser.version<9){
                    
                }
    else if($.browser.version>6&&$.browser.version<8){
                
                }
                h
    =D.documentElement.clientHeight;
            }
            
            
    return h;
        }
        
    /**
         * 取得画板的宽度(即所有内容,当浏览器内容不足的时候为浏览器视图大小)
         
    */
        $.canvasWidth
    =function(){
            
    var D=document,w=D.body.scrollWidth;
            
    if(document.compatMode=='CSS1Compat'){
                w
    =D.documentElement.scrollWidth;
            }
    else{
                
    if($.browser.msie&&$.browser.version<=6&&D.body.scrollWidth>$.viewWidth()){
                    w
    =Math.max(Math.max(D.body.scrollWidth,D.documentElement.scrollWidth),
                        Math.max(D.body.offsetWidth,D.documentElement.offsetWidth),
                        Math.max(D.body.clientWidth,D.documentElement.clientWidth)
                    );
                }
            }
            
    return w;
        }
        
    /**
         * 取得画板的宽度(即所有内容,当浏览器内容不足的时候为浏览器视图大小)
         
    */
        $.scrollLeft
    =function(){
            
    if(document.compatMode!='CSS1Compat'||($.browser.msie&&$.browser.version<=6)){
                
    return Math.max($('body').scrollLeft(),document.documentElement.scrollLeft);
            }
    else{
                
    return $('body').scrollLeft();
            }
            
        }
        
    /**
         * 取得画板的宽度(即所有内容,当浏览器内容不足的时候为浏览器视图大小)
         
    */
        $.scrollTop
    =function(){
            
    if (document.compatMode != 'CSS1Compat'||($.browser.msie&&$.browser.version<=6)) {
                
    return Math.max($('body').scrollTop(), document.documentElement.scrollTop);
            }
    else{
                
    return $('body').scrollTop();
            }
        }
    })(jQuery);
  • 相关阅读:
    正则表达式分组小记
    Python中关于try...finally的一些疑问
    hello,world!
    02操控奴隶——掌握它的语言“Python”
    01操控奴隶——奴隶的构成与运行方式
    vue特殊属性 key ref slot
    vue内置组件 transition 和 keep-alive 使用
    vue文档全局api笔记2
    vue文档全局api笔记1
    vue 二三倍图适配,1像素边框
  • 原文地址:https://www.cnblogs.com/liushannet/p/1961613.html
Copyright © 2011-2022 走看看