Reputation: 1093
I have a menu like bootstrap 3.0 (http://getbootstrap.com/getting-started/) which follows the scroll down and up, but i'd like to have my menu with class "active" corresponding to the div and anchor in the current position of the page.
How can i do this?
this is responsible to follow the scroll
$(window).scroll(function () {
if ($(this).scrollTop() > 90) {
marginTop = ($(document).scrollTop() - scroll) + marginTop;
scroll = $(document).scrollTop();
$("#sideMenu").animate({
"margin-top": marginTop + "px"
}, {
duration: 0,
queue: false
});
}
Upvotes: 0
Views: 49
Reputation: 37431
I believe you're asking about the "scroll spy" feature. You need to determine if the user has scrolled to the content.
A quick example using jQuery would be to compare the $(document).scrollTop
with the offset().top
of the element you care about.
Here's one possible library for doing this
Upvotes: 3