Home  >  Article  >  Web Front-end  >  Commonly used height-width jquery plug-ins for browsers_jquery

Commonly used height-width jquery plug-ins for browsers_jquery

WBOY
WBOYOriginal
2016-05-16 18:10:11904browse
复制代码 代码如下:

(function($) {
/**
* Get the width of the browser view
*/
$.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 ;
}
/**
* Get the height of the browser view
*/
$.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;
}
/**
* Get the height of the artboard (i.e. all content, the browser view size when the browser content is insufficient)
*/
$.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;
}
/**
* Get the width of the artboard (i.e. all content, when the browser content is not enough, it is the browser view size)
*/
$.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;
}
/**
* Get the width of the artboard (i.e. all content, when the browser content is not enough, it is the browser view size)
*/
$.scrollLeft=function(){
if(document.compatMode!='CSS1Compat'||($.browser.msie&&$.browser.version<=6)){
return Math.max($('body').scrollLeft(),document.documentElement.scrollLeft);
}else{
return $('body').scrollLeft();
}
}
/**
* Get the width of the artboard (i.e. all content, when the browser content is not enough, it is the browser view size)
*/
$.scrollTop=function(){
if (document.compatMode != 'CSS1Compat'||($.browser.msie&&$.browser.version<=6)) {
return Math.max($('body').scrollTop(), document.documentElement.scrollTop);
}else{
return $('body').scrollTop();
}
}
})(jQuery);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn