Created
February 11, 2015 17:22
-
-
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
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
$.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