Skip to content

Instantly share code, notes, and snippets.

@michaelBenin
Forked from yckart/README.md
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelBenin/d5715187ec3d244cca32 to your computer and use it in GitHub Desktop.
Save michaelBenin/d5715187ec3d244cca32 to your computer and use it in GitHub Desktop.
(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