Created
November 5, 2018 15:28
-
-
Save rtancman/20a38022a7b24d367805d3b0770aa46e to your computer and use it in GitHub Desktop.
show elements computed style
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
window.getComputedStyle = window.getComputedStyle || function( element ) { | |
return element.currentStyle; | |
} | |
//https://stackoverflow.com/questions/22907735/get-the-computed-style-and-omit-defaults | |
function getStylesWithoutDefaults( element ) { | |
var dummy = document.createElement(element.tagName); | |
document.body.appendChild( dummy ); | |
var defaultStyles = getComputedStyle( dummy ); | |
var elementStyles = getComputedStyle( element ); | |
var diff = {}; | |
for( var key in elementStyles ) { | |
if(elementStyles.hasOwnProperty(key) | |
&& defaultStyles[ key ] !== elementStyles[ key ] ) | |
{ | |
diff[ key ] = elementStyles[ key ]; | |
} | |
} | |
dummy.remove(); | |
return diff; | |
} | |
window.addEventListener("click",function(e){ | |
let x = e.clientX, y = e.clientY, | |
elementMouseIsOver = document.elementFromPoint(x, y) | |
var data = getStylesWithoutDefaults(elementMouseIsOver) | |
console.log(data) | |
},false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment