Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check for scrollable element using jQuery.
/**
* 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