38 posts
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+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
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
  • Located in India
Dhruv says

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

5360 posts The Dude Abides
  • Located in United States
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
+9 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/
1312 posts
  • Has referred 200+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+8 more
LGLab says

Use an old browser? No Candy for You!

:D

+1 for css3

by
by
by
by
by
by