Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jlbruno/1100124 to your computer and use it in GitHub Desktop.
Save jlbruno/1100124 to your computer and use it in GitHub Desktop.
a function to check if a certain element is scrollable, but is NOT showing scrollbars. Useful to use as a test for when you might want to implement another scrolling solution, such as iScroll for iPad.
var isItScrollableWithoutVisibleScrollbars = function(el) {
if (el === null) {
return false;
}
var isScrollable = false;
var hasScrollbars = false;
// first, lets find out if it has scrollable content
isScrollable = el.scrollHeight > el.offsetHeight ? true : false;
// if it's scrollable, let's see if it likely has scrollbars
if (isScrollable) {
hasScrollbars = (el.offsetWidth > el.scrollWidth) ? true : false;
}
if (isScrollable && !hasScrollbars) {
return true;
} else {
return false;
}
};
// example usage
if ( isItScrollableWithoutVisibleScrollbars(plwrap) ) {
playlistScroll = new iScroll('playlist');
}
@stevenvachon
Copy link

@federicoleandroc you should release that as an npm package. "is-scrollable"?

@frannylac
Copy link

@federicoleandroc you should release that as an npm package. "is-scrollable"?

+1

@chrisdemetriad
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment