Skip to content

Commit

Permalink
Stop sticky behaviour if viewport or container is smaller than the st…
Browse files Browse the repository at this point in the history
…icky element.
  • Loading branch information
Craig Morey committed Dec 22, 2014
1 parent 7fcb8b3 commit 43b2a77
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions fixedsticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,21 @@
viewportHeight = $el.data( S.keys.viewportHeight ),
parentOffset = $el.data( S.keys.parentOffset ),
parentHeight = $el.data( S.keys.parentHeight ),
prescrollTop = $el.data(S.keys.prescrollTop);
prescrollTop = $el.data(S.keys.prescrollTop);

// if viewport or container is smaller than sticky element, don't do anything.
if ( elHeight >= ( viewportHeight || parentHeight ) ) {
console.log('x')
unFix();
toggle('initial');
return;
}

function toggle ( newState ) {
$el[ newState=='sticky' ? 'addClass' : 'removeClass' ]( S.classes.active )
[ newState=='initial' ? 'addClass' : 'removeClass' ]( S.classes.inactive )
[ newState=='opposite' ? 'addClass' : 'removeClass' ]( S.classes.opposite );
$el.data( S.keys.state, newState );
[ newState=='opposite' ? 'addClass' : 'removeClass' ]( S.classes.opposite )
.data( S.keys.state, newState );
};

function offTheTop() {
Expand Down

0 comments on commit 43b2a77

Please sign in to comment.