In this tutorial you are going to learn how to make a scroll to top button in HTML
Lets Begin
We are going to use jQuery in this tutorial for some smooth animations, for that we need to include it in the <head> section of the html file. Also we are going to use separate files for css
and javascript so the <head> section will look somewhat like this:
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
Step 1: The HTML code
Just put this tag inside the <body> of the html code after the contents of the page:
<a id="scroll-top" style="display: none;"><span></span></a>
This creates the scroll to top button and next we are going to make an upward arrow symbol in it.Step 2: The CSS code
In this step we are going to create an upward arrow inside the button by using css but you cannot see it because of the inline css style="display: none;" but it does not matter for now because we are going to deal it with javascript, here is the css code:Step 3: The Javascript code
This is the javascript code:Demo
Done
Thank you for reading till the end. Ask questions in the comments section. I will reply as soon as possible. Share this post if you found it helpful.
Comments
Post a Comment