36 posts
  • Envato Studio (Microlancer) Beta Tester
  • Sold between 5 000 and 10 000 dollars
  • Grew a moustache for the Envato Movember competition
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Bought between 100 and 499 items
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
  • Exclusive Author
  • Has been a member for 4-5 years
  • India
Dhruv says

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

5310 posts The Dude Abides
  • United States
  • Exclusive Author
  • Has been a member for 5-6 years
  • Elite Author
  • Bought between 100 and 499 items
  • Referred between 100 and 199 users
  • Author had a Free File of the Month
+5 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
  • Elite Author
  • Sold between 50 000 and 100 000 dollars
  • Has been a member for 6-7 years
  • Envato Studio (Microlancer) Beta Tester
  • United Kingdom
  • Attended a Community Meetup
  • Referred between 200 and 499 users
+3 more
LGLab says

Use an old browser? No Candy for You!

:D

+1 for css3

by
by
by
by
by
by