Skip to content

Instantly share code, notes, and snippets.

@chy4egg
Last active March 30, 2017 10:45
Show Gist options
  • Save chy4egg/94af3578df799dd00f1acf3b47fed80e to your computer and use it in GitHub Desktop.
Save chy4egg/94af3578df799dd00f1acf3b47fed80e to your computer and use it in GitHub Desktop.
Action on scroll script (jQuery)
// jQuery addClass on scroll
var section1 = $('.css-class').offset().top;
var section2 = $('.css-class-2').offset().top;
$(window).scroll(function(){
//section-1
if( $(window).scrollTop() > section1 ) {
$('.css-class').addClass('active'); //добавить класс, когда проскроллил элемент.
} else {
$('.css-class').removeClass('active'); //убрать класс, когда проскроллил обратно.
}
//section-2
if( $(window).scrollTop() > section2 ) {
$('.advantages__fixed-nav-1').addClass('advantages__fixed-nav-2');
} else {
$('.advantages__fixed-nav-1').removeClass('advantages__fixed-nav-2');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment