jquery.scrollTo active anchor link on scroll

I am using the jquery.scrollTo plugin from jquery.scrollTo.
I am trying to figure out how to activate the anchor link on scroll. Can someone help or suggest?
RefaelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RefaelAuthor Commented:
Here is my current code. Again I am trying to find out how to set "active state" on the anchor link while scrolling.

$('ul#submenu-page li a').click(function(e) {		
		e.preventDefault();
		
		var subMenuId = $(this).attr("href");				
		$('ul#submenu-page li').removeClass("active");
		$(this).parent("li").addClass("active");
		
		if (subMenuId==='#section1') {
			$('body, html').scrollTo(0, 1000, {easing:"easeInOutExpo"});			
		} else {		
			$('body, html').scrollTo("#page " + subMenuId, 1000, {easing: "easeInOutExpo", offset:{top:-180}});
		}
	});

Open in new window

0
skijCommented:
Try this:
$('ul#submenu-page li a').click(function(e) {		
		e.preventDefault();
		
		var subMenuId = $(this).attr("href");				
		$('ul#submenu-page li').removeClass("active");
		$(this).parent("li").addClass("active");
		
		if (subMenuId==='#section1') {
			$('body, html').scrollTo(0, 1000, {easing:"easeInOutExpo"});			
		} else {		
			$('body, html').scrollTo("#page " + subMenuId, 1000, {easing: "easeInOutExpo", offset:{top:-180}});
			$("#page " + subMenuId).addClass("active");

		}
	});

Open in new window

0
RefaelAuthor Commented:
skij thank you but....

This is on click function. I talking about the scroll. So when the user scrolls the page and enter e.g. section2 then in the menu with the class "section2" will set to active. Do you know what i mean?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

skijCommented:
0
RefaelAuthor Commented:
skij :-) I actually bookmarked this page while I was searching for the solution.
Yet my current code works so nicely so I do not want to refine everything.
If you will tell me that that's the easy way to go then I will have no choice but to delete my codes and take this one.
0
skijCommented:
The concept there should work with your page, however without seeing all of you code, I don't know for sure.

If you look at it piece by piece you should be able to figure out how to implement the concept.  Here is something to get you started:
$(document).ready(function () {
    $(document).on("scroll", onScroll);
});

function onScroll(event){
    var scrollPos = $(document).scrollTop();
    $('ul#submenu-page li a').each(function () {
        var currLink = $(this);
        var refElement = $(currLink.attr("href"));
        if (refElement.position().top <= scrollPos && refElement.position().top + refElement.height() > scrollPos) {
            $('ul#submenu-page li a').removeClass("active");
            currLink.addClass("active");
        }
        else{
            currLink.removeClass("active");
        }
    });
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RefaelAuthor Commented:
skij you are one of the brilliants :-)  Thank you so much this was very helpful.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.