jquery - unaffix event for Bootstrap affix? -
i want combine affix plugin bootstrap navbar-fixed-top class. far have got working when scroll past navbar gets fixed. when scroll want go static state again. have seen code think older bootstrap versions , unaffix
event. why gone? can create one? or how accomplish trying here?
navbar_secondary = $( '.navbar-secondary:first' ); navbar_secondary.affix( { offset: { top: function () { return (this.top = navbar_secondary.offset().top ) } } } ); navbar_secondary.on( 'affix.bs.affix', function () { // wrong event this. want fire when *not* affixed console.log('affix'); navbar_secondary.removeclass( 'navbar-fixed-top' ).addclass( 'navbar-not-fixed' ); } ); navbar_secondary.on( 'affixed.bs.affix', function () { console.log('affixed'); navbar_secondary.removeclass( 'navbar-not-fixed' ).addclass( 'navbar-fixed-top' ); } );
figured out myself. event names totally confusing. affixed-top.bs.affix
event when goes being not affixed.
navbar_secondary = $( '.navbar-secondary:first' ); navbar_secondary.affix( { offset: { top: function () { return (this.top = navbar_secondary.offset().top ) } } } ); navbar_secondary.on( 'affixed-top.bs.affix', function () { console.log('unaff'); navbar_secondary.removeclass( 'navbar-fixed-top' ).addclass( 'navbar-not-fixed' ); } ); navbar_secondary.on( 'affix.bs.affix', function () { console.log('aff'); navbar_secondary.removeclass( 'navbar-not-fixed' ).addclass( 'navbar-fixed-top' ); } );
summary
affix.bs.affix => before fixed positioning applied element
affixed.bs.affix => after fixed positioning applied element
affix-top.bs.affix => before top element returns original (non-fixed) position
affixed-top.bs.affix => after top element returns original (non-fixed) position
affix-bottom.bs.affix => before bottom element returns original (non-fixed) position
affixed-bottom.bs.affix => after bottom element returns original (non-fixed) position
Comments
Post a Comment