0

I have a link at the top my page which is linked to #here. How can I make the page scroll down to the anchor link with the #here? I've been going to Google and jQuery site, but don't know what to do. The JS code is all I've got.

HTML:

<div class="container">
    <div class="header">
       <a class="link" href="#here">Here</a>
    </div>

    <div class="footer">
       <a id="here"></a>
       <p>Some text...</p>
    </div>
</div>

JS:

$('.link').click(function() {
    $(this).scroll()
});
matzone
  • 5,703
  • 3
  • 17
  • 20
alyus
  • 987
  • 4
  • 20
  • 39

3 Answers3

2

You can add:

$('.link').click(function() {
  $("html, body").animate({ scrollTop: $('#here').offset().top }, 1000);
});
edonbajrami
  • 2,196
  • 24
  • 34
0

If you set the browser's location to the hashtag, then the browser should scroll to that location.

$('.link').click(function() {
   windows.location = $(this).attr('href');
});
Reactgular
  • 52,335
  • 19
  • 158
  • 208
0

This plugin has some nice functionality and features added to it (like different animations): http://demos.flesler.com/jquery/scrollTo/

"All the matched elements will be scrolled, for example:

$('div.pane').scrollTo(...);//all divs w/class pane

If you need to scroll the window (screen), then use:

$.scrollTo(...);//the plugin will take care of this"

JacobMcLock
  • 435
  • 1
  • 3
  • 11