Last active
August 29, 2015 14:11
-
-
Save heyarne/e9170e57b1b77654e53d to your computer and use it in GitHub Desktop.
Find elements too wide for a viewport, causing horizontal scrollbars (jQuery necessary)
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
(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