http://james.padolsey.com/javascript/get-document-height-cross-browser/
Last active
October 22, 2021 20:15
-
-
Save yckart/9128d824c7bdbab2832e to your computer and use it in GitHub Desktop.
Get Viewport dimensions in all browsers. http://stackoverflow.com/a/18136089/1250044
This file contains 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
(function (window, document) { | |
var html = document.getElementsByTagName('html')[0]; | |
var body = document.getElementsByTagName('body')[0]; | |
var ObjectDefineProperty = Object.defineProperty; | |
function define(object, property, getter) { | |
if (!(property in object)) { | |
ObjectDefineProperty(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; }); | |
// OBSOLETE https://developer.mozilla.org/en-US/docs/Web/API/document.height | |
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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for your help :)
hope you have more tips to share for all people :)