How can I make a button return to the top on an html page?
Jquery, javascript, what would be best?
How can I make a button return to the top on an html page?
Jquery, javascript, what would be best?
The best way will depend on your needs.
In addition to the form presented by Mauro, you can use only html pointing the href
of the link to the page stretch that is at the top:
<span id='topo'></span>
<p>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
bla bla <br> bla bla <br> bla bla <br>
</p>
<a href='#topo'>Voltar ao topo</a>
Using Jquery
//scroll normal
$('html,body').scrollTop(0);
//scroll suave
$('html, body').animate({scrollTop:0}, 'slow'); //slow, medium, fast
Using Javascript
var scrollTop = function() {
window.scrollTo(0, 0);
};