Please follow our simple steps to enable scroll to top feature in your website. Also please do not hesitate to ask questions via comments.
|
|
Steps To Add 'Scroll To Top' Feature In Your Web Page Using jQuery
- First open your html code in code editor such as Notepad++ or Dreamviewer, etc.
- Go to <head> section and paste the below code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('a[href=#top]').click(function(){
$('html, body').animate({scrollTop:0}, 'slow');
return false;
});
});
</script>
- Then go to body section and in footer section you can add the link with name Top (<a href="#top" id="top">Top</a>).
- You can even the background to Top link using CSS ( #top { width: 100%; background-color: black; height: 10px; } )
- For you we have given a test code below which you can apply and see effects.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script>
$(document).ready(function() {
$('a[href=#top]').click(function(){
$('html, body').animate({scrollTop:0}, 'slow');
return false;
});
});
</script>
<body>
<a href="#top" id="top">Top</a> <!-- Top Link -->
</body>
</html>