Jsfiddle demo
$('a[href^="#"]').on('click', function(evt){
var target = $($(this).attr('href'));
console.log('target =>' + target);
if(target.length){
evt.preventDefault();
$('html, body').animate(
{scrollTop: target.offset().top}, 1000);
$('a[href^="#"]').removeClass('active');
$(this).addClass('active');
}
});
$(window).scroll(function() {
var windscroll = $(window).scrollTop();
if (windscroll >= 20) {
$('.section').each(function(i) {
if ($(this).position().top <= windscroll - 5) {
$('.scrolling-navigation li a.active').removeClass('active');
$('.scrolling-navigation li a').eq(i).addClass('active');
console.log('top ' + $(this).position().top);
}
});
} else {
$('.scrolling-navigation li a.active').removeClass('active');
$('.scrolling-navigation li a:first').addClass('active');
}
}).scroll();
There are two clicks and scrolling to display points with an active class that colors in black.
Scrolling up and down, points are set correctly and accordingly. But when I tried to click on a point, it is not configured correctly. Only it will be active if you double-click on the same point. In addition, the first point is correctly configured.
Why is it not installed in the active state if you click once on the second point?
source
share