38 posts
  • Author Level 4
  • Beta Tester
  • Collector Level 4
  • Featured Author
+4 more
Thorit
says
Hey, i want to animate (fade in,fade out) my menu when the user scolls down the page. Here is my jQuery code:
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! :)

409 posts
  • 6 Years of Membership
  • Exclusive Author
  • India
Dhruv
says

You can try jQuery( ’.header’ ).addClass( ‘fixed’ ).fadeIn(); and .fadeOut()

5467 posts The Dude Abides
  • Top Monthly Author
  • Trendsetter
  • Weekly Top Seller
  • United States
+13 more
CodingJack
says

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/
1313 posts
  • Affiliate Level 5
  • Author Level 7
  • Beta Tester
  • Collector Level 4
+10 more
LGLab
says

Use an old browser? No Candy for You!

:D

+1 for css3

by
by
by
by
by
by