Skip to content

Instantly share code, notes, and snippets.

@hmowais
Created November 8, 2023 14:17
Show Gist options
  • Save hmowais/1d106995875958d478c1f27c5819c965 to your computer and use it in GitHub Desktop.
Save hmowais/1d106995875958d478c1f27c5819c965 to your computer and use it in GitHub Desktop.
Add Class in Section on Scroll
jQuery( document ).ready(function($) {
var sections = $('.animateiT'),
nav = $('.jump-left'),
nav_height = nav.outerHeight();
$(window).on('scroll', function() {
var cur_pos = $(this).scrollTop();
sections.each(function() {
var top = $(this).offset().top - 300;
var bottom = top + $(this).outerHeight();
if (cur_pos >= top && cur_pos <= bottom) {
nav.find('a').removeClass('animated-div');
sections.removeClass('animated-div');
$(this).addClass('animated-div');
nav.find('a[href="#' + $(this).attr('id') + '"]').addClass('animated-div');
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment