Skip to content

Instantly share code, notes, and snippets.

@andreasisaak
Created December 9, 2016 13:58
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 andreasisaak/1450f00f579a4baee9e7f243c2f7d581 to your computer and use it in GitHub Desktop.
Save andreasisaak/1450f00f579a4baee9e7f243c2f7d581 to your computer and use it in GitHub Desktop.
Debug width and height of elements on resize
var debugItemSize = function () {
var debug = jQuery('.YOUR_CLASS');
debug.each(function () {
var span;
if (jQuery(this).find('.debug-span').length) {
span = jQuery(this).find('.debug-span');
} else {
span = jQuery('<span />').addClass('debug-span');
}
var w = jQuery(this).outerWidth();
var h = jQuery(this).outerHeight();
jQuery(this).prepend(span.html(w + 'x' + h));
jQuery(this).css({
"position": "relative",
"outline": "1px dashed red"
});
jQuery(this).find('.debug-span').css({
"position": "absolute",
"left": "0",
"top": "0",
"background-color": "red",
"color": "white",
"padding": "3px 6px",
"font-family": "sans-serif",
"font-weight": "bold",
"z-index": "99999"
});
});
};
jQuery(window).on('resize', function () {
debugItemSize();
});
debugItemSize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment