Last active
August 29, 2015 14:21
-
-
Save inter-coder/8c2ebe781fb0fd532840 to your computer and use it in GitHub Desktop.
Determine the dimensions of the window or elements
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 element_WH(elem){ | |
var res={}; | |
if(elem==undefined){ | |
res.width = window.innerWidth || html.clientWidth || body.clientWidth || screen.availWidth; | |
res.height = window.innerHeight || html.clientHeight || body.clientHeight || screen.availHeight; | |
}else{ | |
var display=elem.style.display; | |
elem.style.display="block"; | |
res.width = elem.innerWidth || elem.clientWidth; | |
res.height = elem.innerHeight || elem.clientHeight ; | |
elem.style.display=display; | |
} | |
return res; | |
}; | |
element_WH(document.getElementById("someId")); //return JSON, element width and height |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment