Zrobiłem prostą podkładkę dla IE8 i inni:
window.innerWidth
window.innerHeight
window.scrollX
window.scrollY
document.width
document.height
559 bajtów
(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));
Dla aktualizacji, przyjrzeć się tej GIST: 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));
problem ten został rozwiązany w kilku bibliotekach przykład [jQuery] (http://jquery.com) [prototyp] (http://prototypejs.org) [YUI] (http://developer.yahoo.com/yui/), [Zamknięcie] (http://code.google.com/closure/library) lub [dowolne z kilku innych] (http://en.wikipedia.org/wiki/List_of_Java Script_libraries). Zamiast samodzielnie rozwiązywać problemy, możesz rozważyć wykorzystanie pracy innych, abyś mógł skoncentrować się na pisaniu kodu, który jest odpowiedni do twoich wymagań. Ewentualnie zobacz, jak to robią i użyj tego kodu, nawet jeśli nie korzystasz z biblioteki. –
To zostało odebrane przed jakiś czas temu. Sprawdź [to] (http://stackoverflow.com/questions/5864467/internet-explorer-innerheight) – AurA
Z wyjątkiem tego, że iOS '$ (window) .height()' i 'window.innerHeight' zwracają różne wartości. Powiedziałbym więc, że problem nie został jeszcze rozwiązany w takich bibliotekach i nakazach. – cjbarth