Last active
January 3, 2023 21:53
-
-
Save jah2488/3d1a73d7032186fd3e65 to your computer and use it in GitHub Desktop.
Fun little one liner to do some debugging css.
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 debugAll() { | |
[].forEach.call($$('*'), function(a) { | |
function cr() { return 0|(Math.random() * 255); }; | |
a.style.outline = '2px solid rgba(' + [cr(), cr(), cr()].join(',') + ', 0.44)'; | |
}); | |
} |
Bringing this idea to its ultimate conclusion. (requires jquery atm 😒 )
var debuggerAll = function(showTag) {
[].forEach.call($("*"),function(a){
function cr() { return 0|(Math.random() * 255); };
color = 'rgba(' + [cr(), cr(), cr()].join(',') + ', 0.44)';
a.style.outline = "2px solid " + color;
a.style.position = 'relative';
if (showTag) {
style = [
"-webkit-user-select: none",
"user-select: none",
"opacity: 1",
"padding: 0 4px",
"background: " + 'white',
"border: 0px solid " + color,
"font-weight: normal",
"font-size: 18px",
"color: " + color,
"position: absolute",
"bottom: -13px",
"right:0"
];
info = $('<span class="debug" style="' + style.join(';') + '">' + $(a).prop('tagName') + '</span>');
var outlineHover = {'outline-width': '3px', 'z-index': 100000};
var outlineOut = {'outline-width': '1px', 'z-index': 1};
var hoverStyle = {'z-index': 100000, border: '1px solid'};
var outStyle = {'z-index': 1, border: 'none'};
$(a).on('mouseenter',function(){$(this).css(outlineHover);$(this).children('.debug').css(hoverStyle);});
$(a).on('mouseleave', function(){$(this).css(outlineOut);$(this).children('.debug').css(outStyle);});
info.on('mouseenter',function(){$(this).parent().css(outlineHover);$(this).css(hoverStyle);});
info.on('mouseleave', function(){$(this).parent().css(outlineOut); $(this).css(outStyle); });
$(a).append(info);
}
});
}
debuggerAll('show');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could be done this way if you don't care to have nice transparencies.