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

I can't get this to smoothly scroll down to the anchor for some reason. Can anybody see why?

This is the html:

<div id="onward">
<a href="#xdroneslogan" class="btn"><i class="icon-chevron-down icon-white"></i>     Onward</a></div>

This is the javascript:

<script>
$("#onward a").click(function(){
var onwardId = $(this).attr("href");
$("html, body").animate({scrollTop: $(onwardId).offset().top}, "slow");
return false;
});
</script>

2 Answers

Maybe this gives you an idea...Here is the code I'm using for mine.

// scroll
$('a #backtotop').click(function () {
$('body,html').animate({
scrollTop: 0
}, 400);
return false;
});

This is just to scroll to the top of the page though when you click on the link id of backtotop.

Thanks Justin!