I made this code is 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 "anchor" class in the "a" you want to make the anchor effect:
Example:
<a class="ancora" href="#topo">vai para o topo</a>
And in href you put where it goes, for example you put in the first div of your site the top id.
<div id="topo">
So it goes up to the div with the top id.
Example: https://jsfiddle.net/83abc8mq/1/
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: https://jsfiddle.net/83abc8mq/2/
Will you import an entire library just for that purpose? There are simple resolutions of less than 10 lines that does what you want
– Bsalvo
I don’t know if I understood your question correctly, but whenever I need to use animations, I do simulations on the site http://css3generator.com.
– Thainá V.
@thaináv. did not know this, thank you very much!
– Clayton Furlanetto
For nothing, arrange! =)
– Thainá V.