Skip to content
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
12 changes: 10 additions & 2 deletions jquery.stickem.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
$elem: $this,
elemHeight: $this.height(),
$container: $this.parents(_self.config.container),
isStuck: false
isStuck: false,
isStuckAtEnd: false
};

//If the element is smaller than the window
Expand Down Expand Up @@ -125,12 +126,18 @@
var item = _self.items[i];

//If it's stuck, and we need to unstick it, or if the page loads below it
if((item.isStuck && (pos < item.containerStart || pos > item.scrollFinish)) || pos > item.scrollFinish) {
if(((item.isStuck || item.isStuckAtEnd) && (pos < item.containerStart || pos > item.scrollFinish)) || pos > item.scrollFinish) {
item.$elem.removeClass(_self.config.stickClass);

//only at the bottom
if(pos > item.scrollFinish) {
item.$elem.addClass(_self.config.endStickClass);
item.isStuckAtEnd = true;
}

if(pos < item.containerStart) {
item.$elem.removeClass(_self.config.endStickClass);
item.isStuckAtEnd = false;
}

item.isStuck = false;
Expand All @@ -144,6 +151,7 @@
} else if(item.isStuck === false && pos > item.containerStart && pos < item.scrollFinish) {
item.$elem.removeClass(_self.config.endStickClass).addClass(_self.config.stickClass);
item.isStuck = true;
item.isStuckAtEnd = false;

//if supplied fire the onStick callback
if(_self.config.onStick) {
Expand Down