diff --git a/jquery.scroll.js b/jquery.scroll.js index fd80020..231e347 100644 --- a/jquery.scroll.js +++ b/jquery.scroll.js @@ -124,11 +124,6 @@ Changelog: // save content height in properties props.contentHeight = $.fn.scrollbar.contentHeight(container); - // if the content height is lower than the container height, do nothing and return. - if(props.contentHeight <= props.containerHeight){ - return true; - } - // create a new scrollbar object and append to DOM node for later use this.scrollbar = new $.fn.scrollbar.Scrollbar(container, props, options); @@ -139,11 +134,13 @@ Changelog: if(typeof fn === "function"){ fn(container.find(".scrollbar-pane"), this.scrollbar); } + + this.scrollbar.repaint(); }); }, - // repaint the height and position of the scroll handle + // repaint the height and position of the scroll handle // // this method must be called in case content is added or reoved from the container. // @@ -458,10 +455,43 @@ Changelog: // repaint scrollbar height and position // repaint: function(){ + this.setHandleContainerSize(); this.setHandle(); this.setHandlePosition(); }, + // + // update the height of the handleContainer + // + setHandleContainerSize: function() { + var deltaY = this.props.containerHeight - this.container.height(); + + this.props.containerHeight = this.container.height(); + + // hide the scroller if the content height is lower than the + // container height + if(this.props.contentHeight <= this.props.containerHeight) { + this.handleContainer.hide(); + this.handleArrowDown.hide(); + this.handleArrowUp.hide(); + } else { + this.handleContainer.show(); + this.handleArrowDown.show(); + this.handleArrowUp.show(); + } + + this.handleContainer.css({ + 'position': 'absolute', + 'top': this.handleArrowUp.outerHeight(true), + 'height': (this.props.containerHeight - this.handleArrowUp.outerHeight(true) - this.handleArrowDown.outerHeight(true)) + 'px' + }); + + // Scroll up content as container gets bigger. + this.handle.top -= deltaY; + this.setHandlePosition(); + this.setContentPosition(); + }, + // // scroll to a specific distance from the top