Reputation: 6646
Developing a single page (body scroll top animation ) Please check demo first and see add/remove active classes on 'menu li a' http://jsfiddle.net/sUMaa/1/
Everything is fine but single problem Need same active class function while we page scrolling with the mouse
jQuery('ul li a').click(function(){
var idName = jQuery(this).attr('href');
var idNameFixTop = jQuery(idName).offset().top;
jQuery('html, body').animate({scrollTop:idNameFixTop}, 1000);
jQuery('ul li a').removeClass('active');
jQuery(this).addClass('active');
});
Upvotes: 0
Views: 2839
Reputation: 1392
Either way, you can use twitter bootstrap Scrollspy, works fine :)
Upvotes: 1
Reputation: 8230
Although I understand your problem, implementing this on your own may raise some tricky questions:
To make your life easier, use something like the jQuery Waypoints plugin. Take a look at the Docs, you can control pretty much everything.
Example for your code:
$('div').waypoint(function() {
$('ul li a').removeClass('active');
var currentIndex = $('div').index($(this));
$('ul li:eq(' + currentIndex + ') a').addClass('active');
},
{
offset: 'bottom-in-view'
});
Upvotes: 1