I made this code very simple to use:
$(function () {
var $doc = $('html, body');
$('.ancora').click(function () {
$doc.animate({
scrollTop: $($(this).attr('href')).position().top
}, 700);
return false;
});
});
You add the class "anchor" in the "a" you want to do the anchor effect:
Example:
<a class="ancora" href="#topo">vai para o topo</a>
And in the href you put it where it goes, for example you put in the first div of your site the top id.
<div id="topo">
So it goes to the div with the top id.
Example: link
If you want a horizontal scroll:
$(function () {
var $doc = $('html, body');
$('.ancora').click(function () {
$doc.animate({
scrollLeft: $($(this).attr('href')).position().left
}, 700);
return false;
});
});
Example: link