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