Solved

Adding ScrollTo effect to links, multiple on the same page, to different locations

Posted on 2011-03-21
6
451 Views
Last Modified: 2012-05-11
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:

<a id="dest1"></a>
<a id="dest2"></a>
<a id="dest3"></a>

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:

<script type="text/javascript">
      $(function(){
            $('.pagescroll').click(function(){
                  var linkId=$(this).attr('id');
                  var linkNum=parseInt(linkId, 10);
                  var linkTo='dest'+linkNum;
                  $scrollTo(linkTo,'slow',{axis:'y'});
            });
      });
</script>

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.

Thank you!
0
Comment
Question by:bbdesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:chuckalicious
ID: 35184781
I think you need a plugin for scrollTo...

http://demos.flesler.com/jquery/scrollTo/

0
 

Author Comment

by:bbdesign
ID: 35189228
I have the plugin loaded. Here is my sample page:

http://secure.bbdesign.com/lighthousechristiancenter/support-groups.asp
0
 
LVL 4

Accepted Solution

by:
chuckalicious earned 500 total points
ID: 35189264
Ok I think this is as straight forward as you having missed the "." between $ and scrollTo

Change this line:

$scrollTo(linkTo,'slow',{axis:'y'});

to

$.scrollTo(linkTo,'slow',{axis:'y'});
0
What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

 

Author Comment

by:bbdesign
ID: 35189335
I added that, but still doesn't go anywhere.
0
 

Author Comment

by:bbdesign
ID: 35189375
Wait, I found it:

$.scrollTo('#'+linkTo,'slow',{axis:'y'});

You pass the # to identify it as an ID, then it works. Thanks!
0
 

Author Comment

by:bbdesign
ID: 35189380
But it did also need the period.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question