A while back I found the following script on stackoverflow and it seems to work well... for initial page load, but I need to somehow make this more responsive. I need it to somehow fire when the browser changes size and when a div appears after the page is loaded. Basically "live" and firing all the time when needed. I've tried tweaking it but always fail. I also need it for two different target divs. Any tips greatly appreciated :)
(function($) {
$.fn.has_scrollbar = function() {
var divnode = this.get(0);
if(divnode.scrollHeight > divnode.clientHeight)
return true;
}
})(jQuery);
example:
if($('#scrollable').has_scrollbar()) { $("#scrollable").css({"width":"97%"});
}
UPDATE:
This is pretty close to working, I need a way to undo the width adjustment if the scrollbar disappears. Would an if / else statement do that, or I need a new function to detect no presence of scrollbar and then run a new document.ready wrapper saying #xxx width 100%?
function bindHasScrollbar() {
(function($) {
$.fn.has_scrollbar = function() {
var divnode = this.get(0);
if(divnode.scrollHeight > divnode.clientHeight)
return true;
}
})(jQuery);
}
$(document).ready(function() {
// Initial
bindHasScrollbar();
$("#story").css({"width":"97%"});
$("#minigallery").css({"width":"97%"});
// Refresh
$(window).resize(function() {
bindHasScrollbar();
$("#story").css({"width":"97%"});
$("#minigallery").css({"width":"97%"});
});
});