var $window = jQuery( window );
$window.scroll( function() {
if( $window.scrollTop() > 110 ) {
jQuery( '.header' ).addClass( 'fixed' );
}
else if( $window.scrollTop() <= 560 ) {
jQuery( '.header' ).removeClass( 'fixed' );
}
});
How can i animate this add/remove class action?
Thanks in advance! 
You can try jQuery( ’.header’ ).addClass( ‘fixed’ ).fadeIn(); and .fadeOut()
- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
You can do this with CSS3
Just add these properties below to your “fixed” class, then add the “fixed-visible” rule to the stylesheet, and last, change “fixed” to “fixed-visible” in your JS where to use addClass and removeClass.
.fixed {
opacity: 0;
visibility: hidden;
-webkit-transition: all 0.6s cubic-bezier(0.230, 1.000, 0.320, 1.000);
-moz-transition: all 0.6s cubic-bezier(0.230, 1.000, 0.320, 1.000);
-o-transition: all 0.6s cubic-bezier(0.230, 1.000, 0.320, 1.000);
-ms-transition: all 0.6s cubic-bezier(0.230, 1.000, 0.320, 1.000);
transition: all 0.6s cubic-bezier(0.230, 1.000, 0.320, 1.000);
}
.fixed-visible {
opacity: 1;
visibility: visible;
}
It’s fallback-proof for browsers that don’t support CSS3 transitions. And in those cases, the menu just won’t animate. But my philosophy on this is: Use an old browser? No Candy for You!
Also, here are some more transitions you can use:
http://matthewlein.com/ceaser/
