Created
May 1, 2015 12:19
-
-
Save davidvandenbor/814d951cb71ff4e63db6 to your computer and use it in GitHub Desktop.
Add CSS code or classes to html elements with jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @david: add or remove classes at certain scrolling distances | |
| // the class names in this gist are meant as an example :-) | |
| $(window).scroll(function() { | |
| var y_scroll_pos = window.pageYOffset; | |
| var scroll_pos_test = 300; | |
| // set to whatever you want it to be | |
| if (y_scroll_pos > scroll_pos_test) { | |
| $(".menu").addClass("animated fadeInLeft"); | |
| // or add or remove pure CSS code: | |
| $(".your-class").css({ | |
| "opacity": "0" | |
| }); | |
| $('.other-class').css({ | |
| "transition": "all .5s ease-in-out 0s", | |
| "opacity": "0" | |
| }); | |
| // end of additional css code | |
| } | |
| else | |
| { | |
| $(".menu").removeClass("animated fadeInLeft"); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment