Skip to content

Instantly share code, notes, and snippets.

@danbrianwhite
Last active December 16, 2015 05:28
Show Gist options
  • Save danbrianwhite/bcdd7fbd6d775a4e0dc0 to your computer and use it in GitHub Desktop.
Save danbrianwhite/bcdd7fbd6d775a4e0dc0 to your computer and use it in GitHub Desktop.
polyfill window.offsetWidth and window.offsetHeight
//polyfill window.offsetWidth and window.offsetHeight
var windowOffset = function()
{
var getOffset = function()
{
if(typeof(_cacheResize) === "function")
{
_cacheResize
}
window.offsetWidth = (function()
{
if(window.innerWidth!= undefined)
{
return window.innerWidth;
}
else
{
var _b= document.body,
_d= document.documentElement;
return Math.max(_d.clientWidth, _b.clientWidth);
}
})();
window.offsetHeight= (function()
{
if(window.innerHeight!= undefined)
{
return window.innerHeight;
}
else
{
var _b= document.body,
_d= document.documentElement;
return Math.max(_d.clientHeight, _b.clientHeight);
}
})();
}
var _cacheResize = window.onresize;
window.onresize = function()
{
_cacheResize();
getOffset();
}
getOffset();
}
//invoke function
windowOffset();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment