Go to the "home" page [duplicate]

0

How can I do this through a javascript function, which activates the "Home" command, ie the page jumps to the top of it? Example: A button that is clicked at the bottom of the page redirects overflow to the top.

    
asked by anonymous 01.03.2018 / 16:43

1 answer

1

You can do this 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>
    
01.03.2018 / 16:46