Go to "home" page

Asked

Viewed 40 times

0

How can I do through a javascript function, which is enabled the command "Home", ie the page make a jump to the top of it? Example: A button that is clicked and is at the bottom of the page, redirects the overflow for the start (top).

  • You can only do this with HTML using Ancoras. https://www.codigofonte.net/dicas/html/29_creation-ncoras-em-suas-p-ginas will only need JS if you want to make the BTN appear at a certain point in the Scroll or if the Scroll effect is smooth or progressive like this

1 answer

1

You can do so with jQuery

var body = $("html, body");

$('button').click(function(){
  body.stop().animate({scrollTop:0}, 500, 'swing', function() { 
  
});
})
p{
  margin-top: 500px;
  
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>OiM</p>

<button>Voltar</button>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.