Skip to content

Instantly share code, notes, and snippets.

@heyarne
Last active August 29, 2015 14:11
Show Gist options
  • Save heyarne/e9170e57b1b77654e53d to your computer and use it in GitHub Desktop.
Save heyarne/e9170e57b1b77654e53d to your computer and use it in GitHub Desktop.
Find elements too wide for a viewport, causing horizontal scrollbars (jQuery necessary)
(function ($) {
var bodyWidth = $(document.body).outerWidth();
var $elems = $('body *').filter(function () {
var $this = $(this)
return $this.offset().left + $this.outerWidth(true) - parseInt($this.css('margin-left'), 10) > bodyWidth
})
if ($elems.length)
console.log($elems)
else
console.log('No elements found, maybe a :before or :after pseudo element is causing the overflow.')
return $elems
})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment