How to Create Scroll to Top of the Page by JQuery Animate?

By Hardik Savani February 6, 2023 Category : PHP Javascript HTML jQuery

However you want the scrolling process to have animated effect. you have to follow bellow example. in this post you can add button for scrolling top with animate effect. Most of website you can see with one button left side or right side for scrolling top of the page. so, if you want to create on your site then you have to add following jquery code:


<!DOCTYPE html>



<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">


<style type="text/css">


position: fixed;

bottom: 20px;

left: 20px;

cursor: pointer;

display: none;

z-index: 999999;

background: #5a5a5a none repeat scroll 0 0;

display: block;

padding: 12px 15px;





<script type="text/javascript">


$('body').append('<div id="toTopImg" style="display:none">Top</div>');

$(window).scroll(function () {

if ($(this).scrollTop() != 0) {


} else {





$("html, body").animate({ scrollTop: 0 }, 600);

return false;






I hope it can help you...

Tags :