Skip to content

Instantly share code, notes, and snippets.

@rtancman
Created November 5, 2018 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtancman/20a38022a7b24d367805d3b0770aa46e to your computer and use it in GitHub Desktop.
Save rtancman/20a38022a7b24d367805d3b0770aa46e to your computer and use it in GitHub Desktop.
show elements computed style
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