I am using twitter bootstrap for my site.The navbar link get active on click but i want same effect when i scroll to particular section of the page. i.e (links turns grey on click, i want same effect when i scroll on that section)
// jQuery code
$(document).ready(function() {
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 50
}, 1000);
return false;
}
}
});
});
$('.nav li a').on('click', function() {
$(this).parent().parent().find('.active').removeClass('active');
$(this).parent().addClass('active');
});
});
I have tried using twitters scrollspy but because of this line of code scrollTop: target.offset().top - 50 i am having some problem. Example When i click on Contact it goes on contact section but portfolio link is active in navigation menu.
My Site: www.nakibmomin.com