Skip to content

Instantly share code, notes, and snippets.

@jah2488
Last active January 3, 2023 21:53
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jah2488/3d1a73d7032186fd3e65 to your computer and use it in GitHub Desktop.
Save jah2488/3d1a73d7032186fd3e65 to your computer and use it in GitHub Desktop.
Fun little one liner to do some debugging css.
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)';
});
}
@jah2488
Copy link
Author

jah2488 commented Oct 12, 2014

Could be done this way if you don't care to have nice transparencies.

[].forEach.call($$("*"),function(a){
  a.style.outline="2px dashed #"+(Math.random().toString(16).slice(-6))
})

@jah2488
Copy link
Author

jah2488 commented Mar 29, 2015

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