Adding ScrollTo effect to links, multiple on the same page, to different locations
Posted on 2011-03-21
I am trying to learn jQuery, so please bare with me. I have a series of links that look like this:
<a class="pagescroll" id="1goto" href="#">link</a>
<a class="pagescroll" id="2goto" href="#">link</a>
<a class="pagescroll" id="3goto" href="#">link</a>
Then I have anchors like these, positioned further down the page:
My thinking is that I can use jQuery to identify this type of link by the class, then take the link's ID to identify where in the page it should scroll to (goto1 scrolls to the ID desc1). I don't know if this is the best/most efficient way to do it, so I'm open to suggestions.
My non-working script looks like this:
var linkNum=parseInt(linkId, 10);
linkTo is populating correctly, if you click the link with 3goto it will populate linkTo with dest3, so I just need to figure out how to get the scrollTo to take that variable and use it to scroll to the element with the ID of linkTo.