Created
June 27, 2014 03:19
-
-
Save kiinlam/13219c4ec57de2e3a7a8 to your computer and use it in GitHub Desktop.
获取窗口尺寸函数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getDocRect = function(doc){ | |
doc = doc || document; | |
var win = doc.defaultView || doc.parentWindow, | |
mode = doc.compatMode, | |
root = doc.documentElement, | |
h = win.innerHeight || 0, | |
w = win.innerWidth || 0, | |
scrollX = win.pageXOffset || 0, | |
scrollY = win.pageYOffset || 0, | |
scrollW = root.scrollWidth, | |
scrollH = root.scrollHeight, | |
offsetW,offsetH; | |
if (mode != 'CSS1Compat') { // Quirks | |
root = doc.body; | |
scrollW = root.scrollWidth; | |
scrollH = root.scrollHeight; | |
} | |
if (mode && !Browser.opera) { // IE, Gecko | |
w = root.clientWidth; | |
h = root.clientHeight; | |
} | |
scrollW = Math.max(scrollW, w); | |
scrollH = Math.max(scrollH, h); | |
scrollX = Math.max(scrollX, doc.documentElement.scrollLeft, doc.body.scrollLeft); | |
scrollY = Math.max(scrollY, doc.documentElement.scrollTop, doc.body.scrollTop); | |
offsetW =document.body.offsetWidth||document.documentElement.offsetWidth; | |
offsetH = document.body.offsetHeight||document.documentElement.offsetHeight; | |
return { | |
width: w, | |
height: h, | |
scrollWidth: scrollW, | |
scrollHeight: scrollH, | |
scrollX: scrollX, | |
scrollY: scrollY, | |
contentWidth:(scrollW == w ? offsetW:scrollW), | |
contentHeight:(scrollH == h ? offsetH:scrollH) | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment