Skip to content

Instantly share code, notes, and snippets.

@davidvandenbor
Created May 1, 2015 12:19
Show Gist options
  • Select an option

  • Save davidvandenbor/814d951cb71ff4e63db6 to your computer and use it in GitHub Desktop.

Select an option

Save davidvandenbor/814d951cb71ff4e63db6 to your computer and use it in GitHub Desktop.
Add CSS code or classes to html elements with jQuery
// @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