Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust for dynamically changed container size. #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions jquery.scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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.
//
Expand Down Expand Up @@ -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
Expand Down