ItSolutionStuff.com

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

By Hardik Savani • February 6, 2023
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:

Example

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

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

<title></title>

<style type="text/css">

#toTopImg{

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;

}

</style>

</head>

<body>

<script type="text/javascript">

$(document).ready(function(){

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

$(window).scroll(function () {

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

$('#toTopImg').fadeIn();

} else {

$('#toTopImg').fadeOut();

}

});

$('#toTopImg').click(function(){

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

return false;

});

});

</script>

</body>

</html>

I hope it can help you...

Tags: jQuery
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

JQuery Remove All Numbers from String Example

Read Now →

How to Download File using JQuery?

Read Now →

Laravel JQuery UI Autocomplete Ajax Search Example

Read Now →

How to Check Atleast One Checkbox is Checked or Not in JQuery?

Read Now →

JQuery - How to Get X and Y Position of an Element on Click Event?

Read Now →

Jquery Moment Convert String to Date Example

Read Now →

JQuery Moment JS Subtract Seconds to Datetime Example

Read Now →

JQuery Moment Add Hours to Datetime Example

Read Now →

How to Remove Key Value from Array using JQuery?

Read Now →

How to Remove Duplicate Value from Array in JQuery?

Read Now →

How to Call AngularJS Controller Function in JQuery?

Read Now →

JQuery Hide and Show Password using Eye Icon Example

Read Now →

How to Check Object is Empty or Not in JQuery?

Read Now →

Autocomplete with Images and Custom HTML Code in Jquery UI?

Read Now →