Skip to content

Instantly share code, notes, and snippets.

@inter-coder
Last active August 29, 2015 14:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save inter-coder/8c2ebe781fb0fd532840 to your computer and use it in GitHub Desktop.
Determine the dimensions of the window or elements
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