Created
July 15, 2013 19:29
-
-
Save aubricus/6002683 to your computer and use it in GitHub Desktop.
Check for scrollable element using jQuery.
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
/** | |
* Test to get correct scrollable element | |
* @return {string} | |
* @see http://www.zachstronaut.com/posts/2009/01/18/jquery-smooth-scroll-bugs.html (updated to use $.scrollTop()) | |
* @requires jquery 1.7+ | |
*/ | |
getScrollable = function(){ | |
var result = 'html, body', | |
initScrollTop; | |
$('html, body').each(function(){ | |
var $this = $(this); | |
initScrollTop = $this.scrollTop(); | |
$this.scrollTop(initScrollTop +1); | |
if($this.scrollTop() === initScrollTop + 1){ | |
result = this.nodeName.toLowerCase(); | |
$this.scrollTop(initScrollTop); | |
return result; | |
} | |
}); | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment