The*_*lis 26 javascript jquery internet-explorer-8
我有一些依赖的计算window.innerHeight.但正如我发现这在IE9之前的任何IE中都不可用.我所看到的所有其他选项甚至都没有接近我使用时得到的数字window.innerHeight.
有人有工作吗?
San*_*hak 48
您可能想尝试:
document.documentElement.clientHeight;
或者可以使用jQuery的.height()方法:
$(window).height();
yck*_*art 14
我为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));