首页 > 代码库 > 获取文档高度
获取文档高度
var Browser = (function(){ var na = window.navigator, ua = na.userAgent.toLowerCase(), browserTester = /(msie|webkit|gecko|presto|opera|safari|firefox|chrome|maxthon|android|ipad|iphone|webos|hpwos)[ \/os]*([\d_.]+)/ig, Browser = { platform: na.platform }; ua.replace(browserTester, function(a, b, c) { var bLower = b.toLowerCase(); if (!Browser[bLower]) { Browser[bLower] = c; } }); if (Browser.opera) { //Opera9.8后版本号位置变化 ua.replace(/opera.*version\/([\d.]+)/, function(a, b) { Browser.opera = b; }); } if (Browser.msie) { Browser.ie = Browser.msie; var v = parseInt(Browser.msie, 10); Browser[‘ie‘ + v] = true; } return Browser; })();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) }; };
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。