A simple Scroll to Top Button using JQuery


 A simple Scroll to Top Button using JQuery

 

 

For any website, it is necessary having smooth scroll feature to scroll to a particular page top section while browsing website pages.  In this code example, when a visitor clicks on the 'scrolltotop' button in the bottom of the page, that enables smooth scrolling and takes the user to the top of the page.


Here’s the jQuery snippet to A simple Scroll to Top Button.



<!DOCTYPE html>
<html>
<head>
	
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> 
<!--SMOOTH SCROLL -->
<script>
	$(function() {
		$('a[href*=\\#]:not([href=\\#])').on('click', function() {
			var target = $(this.hash);
			target = target.length ? target : $('[name=' + this.hash.substr(1) +']');
			if (target.length) {
				$('html,body').animate({
					scrollTop: target.offset().top
				}, 1000);
				return false;
			}
		});
	});
</script>
</head>
<body>
	
<div class="container-fluid">
<div name="top"> </div>  

Click the Scroll Top Button see the effect!		
<div style="background-color:lightgrey;padding:30px 30px 2500px">
<h3>This example demonstrates how scrolltotop button works..</h3>

<strong>when the user clicks  it. </strong>. 
</div>
<div class="row">
		<div class="col-md-12 bg-light text-right">
		   <a href="#top"  class="btn btn-primary">
		   <i class="fa fa-arrow-up" aria-hidden="true"></i> </a>
	   </div> 
</div>	
	</body>
</html>

 



e-trainings-scroll2top-smoothscroll-button

Comments

Popular posts from this blog

Recently viewed list in PHP Mysql

Import CSV File Into MySQL Using PHP

Shoppingcart using PHP Sessions - Miniproject