Last active
December 16, 2015 05:28
-
-
Save danbrianwhite/bcdd7fbd6d775a4e0dc0 to your computer and use it in GitHub Desktop.
polyfill window.offsetWidth and window.offsetHeight
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
//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