Last active
December 13, 2015 20:48
-
-
Save andreiglingeanu/4972293 to your computer and use it in GitHub Desktop.
getComputedStyle for IE
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 getIEComputedStyle(elem, prop) { | |
var value = elem.currentStyle[prop] || 0 | |
// we use 'left' property as a place holder so backup values | |
var leftCopy = elem.style.left | |
var runtimeLeftCopy = elem.runtimeStyle.left | |
// assign to runtimeStyle and get pixel value | |
elem.runtimeStyle.left = elem.currentStyle.left | |
elem.style.left = (prop === "fontSize") ? "1em" : value | |
value = elem.style.pixelLeft + "px"; | |
// restore values for left | |
elem.style.left = leftCopy | |
elem.runtimeStyle.left = runtimeLeftCopy | |
return value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment