Skip to content

Instantly share code, notes, and snippets.

@ksk1015
Last active December 9, 2016 08:00
Show Gist options
  • Save ksk1015/4728c3d44c0d93740fdd55180d1f24d5 to your computer and use it in GitHub Desktop.
Save ksk1015/4728c3d44c0d93740fdd55180d1f24d5 to your computer and use it in GitHub Desktop.
window.scrollMaxX, window.scrollMaxY polyfill, add scrollMaxX, scrollMaxY to HTMLElement.
// window.scrollMaxX, window.scrollMaxY polyfill
'scrollMaxX' in window || Object.defineProperties(window, {
scrollMaxX: {
enumerable: true,
get: function(){
return document.documentElement.scrollWidth - document.documentElement.clientWidth;
},
},
scrollMaxY: {
enumerable: true,
get: function(){
return document.documentElement.scrollHeight - document.documentElement.clientHeight;
},
}
});
// add scrollMaxX, scrollMaxY to HTMLElement
'scrollMaxX' in HTMLElement || Object.defineProperties(HTMLElement.prototype, {
scrollMaxX: {
enumerable: true,
get: function(){
return this.scrollWidth - this.clientWidth;
},
},
scrollMaxY: {
enumerable: true,
get: function(){
return this.scrollHeight - this.clientHeight;
},
}
});
@ksk1015
Copy link
Author

ksk1015 commented Dec 9, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment