views:

26

answers:

1

I'm a noob with jQuery and I know about scrollTo, but not quite how to get it to function on my site. I did a quick Google search and found lots of results, but at a glance the most reliable one (or at least most popular) currently used is this one: http://plugins.jquery.com/project/ScrollTo

However, again, being a total noob to scripting, not exactly sure how to use it to accomplish my task. (HTML and CSS are my bag, baby).

So here's what I'm trying to do...very simple stuff I'm sure.

On http://joelglovier.com I'm building a one page "gateway" site with links to lots of my other fun web content. I have a top navigation which simply just links to anchors further down the page. All I want is for scrollTo to take my users down to those anchors in a nice, animated fashion. Told you this was simple!

Any help appreciated on the best way to implement this, and whether there is a current standard for this type of scrollTo use (I see it everywhere nowadays).

+2  A: 

refer : .offset(), .scrollTop() , .animate()

you can do some thing like

$(function() {
    $('#nav-find-me-at a').click(function() {
        var pos = $('#find-me-at').offset().top;
        $('html, body').animate({'scrollTop' : pos}, 1000);
            return false;
    });
});

edit : test it here : http://jsbin.com/ecaye

Ninja Dude
Yeah, that seems to work, but aren't "scrollTop" and "scrollTo" different functions for different purposes? Isn't "scrollTop" for scrolling to the top of a page from the bottom? So wouldn't this be like using is in a backwards fashion?
JAG2007
Also, the animation looks kinda choppy when I tried it. I'm viewing from Chrome.
JAG2007
I haven't experience any choppiness while running on chrome !
Ninja Dude
Maybe it has to do with how I put it in. I added in the head, but I also have some jQuery before the end body tag. Not sure how to properly combine them though.
JAG2007
just checked your page. lol, you have copied the above code as it is. un wrap the code from anonymous function, i.e., just remove `$(function(){` part.
Ninja Dude
Cool - that works MUCH better! Do I have my statement closed properly?
JAG2007
yes, you need to close em properly, if not you may end up with errors. Have a Nice Day !!
Ninja Dude