Created
November 8, 2023 14:17
-
-
Save hmowais/1d106995875958d478c1f27c5819c965 to your computer and use it in GitHub Desktop.
Add Class in Section on Scroll
This file contains 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
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