Created
December 9, 2016 13:58
-
-
Save andreasisaak/1450f00f579a4baee9e7f243c2f7d581 to your computer and use it in GitHub Desktop.
Debug width and height of elements on resize
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
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