Skip to content

Instantly share code, notes, and snippets.

@DiegoSalazar
Created February 11, 2015 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoSalazar/43f58fde3fec791dba2e to your computer and use it in GitHub Desktop.
Save DiegoSalazar/43f58fde3fec791dba2e to your computer and use it in GitHub Desktop.
Tiny jQuery plugin to hide/show an element when a target element gets scrollbars
$.fn.hideWhenNoScrollBars = function() {
return this.each(function() {
var el = $(this),
target = $(el.data('target'));
function hideWhenNoScrollbars(target, el) {
if (target.scrollHeight > target.clientHeight) { // has vertical scrollbars
el.show();
} else {
el.hide();
}
}
$(window).on('resize', function() {
hideWhenNoScrollbars(target[0], el);
});
hideWhenNoScrollbars(target[0], el);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment