Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Jquery smooth scrolling.

Good day all. I am trying to add smooth scrolling on my website since is one page side. I watched the smooth scrolling videos,but my nav menu is not scrolling down slowly. What am I doing wrong here? Here is my code and thank you.

<ul class="main-nav">
  <li><a href="index.html">Home</a></li>
  <li><a href="#about">About</a></li>
   <li><a href="#contact">Contact</a></li>
</ul>
$("main-nav a").click(function() {
    var navHeader = $(this).attr("href");
    $("body").animate({scrollTop: $(navHeader).offset.top},"slow");
    return false;
});

3 Answers

You could give your anchor tags a class to hook them.

I just did but my nav is not even scrollind down now. Here is my code again

    <ul class="main-nav">
                <li><a href="index.html" class="smoothscrolling">Home</a></li>
                <li><a href="#about" class="smoothscrolling">About</a></li>
                <li><a href="#contact" class="smoothscrolling">Contact</a></li>
            </ul>
   $(".smoothscrolling").click(function() {
    var navHeader = $(this).attr("href");
    $("body").animate({scrollTop: $(navHeader).offset.top},40000);
    return false;
});

try the code you had before but with "main-nav > a" instead.

Nope, is not even working still.