我有一些依赖于window.innerHeight的计算。但据我所知,在IE9之前的任何IE中都没有这个功能。我研究过的所有其他选项甚至都不能接近我使用window.innerHeight时得到的数字。
有人在这附近工作吗?
发布于 2012-04-16 19:35:33
您可能想要尝试:
document.documentElement.clientHeight;或者可以使用jQuery's .height()方法:
$(window).height();发布于 2013-08-09 05:05:01
我为IE8和其他程序创建了一个简单的填充程序:
window.innerWidthwindow.innerHeightwindow.scrollXwindow.scrollYdocument.widthdocument.height559字节
(function(d,b){var c=b.documentElement;var a=b.body;var e=function(g,h,f){if(typeof g[h]==="undefined"){Object.defineProperty(g,h,{get:f})}};e(d,"innerWidth",function(){return c.clientWidth});e(d,"innerHeight",function(){return c.clientHeight});e(d,"scrollX",function(){return d.pageXOffset||c.scrollLeft});e(d,"scrollY",function(){return d.pageYOffset||c.scrollTop});e(b,"width",function(){return Math.max(a.scrollWidth,c.scrollWidth,a.offsetWidth,c.offsetWidth,a.clientWidth,c.clientWidth)});e(b,"height",function(){return Math.max(a.scrollHeight,c.scrollHeight,a.offsetHeight,c.offsetHeight,a.clientHeight,c.clientHeight)});return e}(window,document));有关更新,请查看以下要点:yckart/9128d824c7bdbab2832e
(function (window, document) {
var html = document.documentElement;
var body = document.body;
var define = function (object, property, getter) {
if (typeof object[property] === 'undefined') {
Object.defineProperty(object, property, { get: getter });
}
};
define(window, 'innerWidth', function () { return html.clientWidth });
define(window, 'innerHeight', function () { return html.clientHeight });
define(window, 'scrollX', function () { return window.pageXOffset || html.scrollLeft });
define(window, 'scrollY', function () { return window.pageYOffset || html.scrollTop });
define(document, 'width', function () { return Math.max(body.scrollWidth, html.scrollWidth, body.offsetWidth, html.offsetWidth, body.clientWidth, html.clientWidth) });
define(document, 'height', function () { return Math.max(body.scrollHeight, html.scrollHeight, body.offsetHeight, html.offsetHeight, body.clientHeight, html.clientHeight) });
return define;
}(window, document));发布于 2013-08-09 21:09:30
在您的document.ready中使用以下内容,并显式定义innerHeight。
window.innerHeight = window.innerHeight || document.documentElement.clientHeighthttps://stackoverflow.com/questions/10173236
复制相似问题