Skip to content

Instantly share code, notes, and snippets.

@cmawhorter
Last active September 2, 2016 07:38
Show Gist options
  • Select an option

  • Save cmawhorter/3a152aa8366c4b557ba7 to your computer and use it in GitHub Desktop.

Select an option

Save cmawhorter/3a152aa8366c4b557ba7 to your computer and use it in GitHub Desktop.
Checks every element in a page to see if it's total width is wider than the container (viewport by default). Might be useful to track down unwanted horizontal scroll bars.
// Deps on jquery
(function(container) {
var viewportWidth = $(container).width();
console.group('Overflow Check');
console.info('Container Width: %s', viewportWidth);
$('*').each(function() {
var $this = $(this);
var elWidth = $this.outerWidth(true);
if (elWidth > viewportWidth) {
console.warn('Overflow by %spx!', elWidth - viewportWidth, loggingVars, this);
}
else {
console.debug('Element OK', elWidth, this);
}
});
console.groupEnd('Overflow Check');
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment