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
+3 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()

5406 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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by