At present, lots of websites use a separate button for the user to get back to the top of the webpage. When viewers scroll down to explore more about the website, they sometimes need to get back to the top of the page for some reason. What If any website doesn't have a scroll to the top button? In that case, the visitor manually go back to the top of the website by scrolling. This experience sometimes may irritate the user, and they might not feel right. For this purpose, web designers, nowadays use the dynamic and animated jQuery scroll-to-top button in their website design. It will save a tremendous amount of time for the visitors, and they will have a good impression of the website.
Video Tutorial:
So we are assuming you have watched the demo. For making the project of Back To Top or Scroll To Top Button, we have used simple HTML and CSS code and a little bit of jQuery. These codes will be easy to understand and implement. If you like to add this project (Scroll To Top Button) and want the code, you have to scroll down and get this project's code.
Before sharing the code, We would like to talk a bit about this snippet (Scroll to Top with JQuery). We first created a div element named ''banner' and placed a simple h1 tag with some random text. After that, inside a div, We took another div called 'content,' and inside that, We have taken an h2 tag and paragraph tag with some lorem ipsum text. Here, content div is self-explanatory and indicates the contents that we see under any website's main banner.
You may also like:
Underneath the div, We have taken an anchor tag and named that 'scrollUp.' We also placed a font-awesome icon inside it. We have chosen the 'chevron-up' icon from all the font-awesome icons because that will be the best fit for this project.
In the CSS styling, We first fixed the default margin padding problem of the document by giving the universal selector a zero margin padding. After that, We used the CSS flex property to bring the h1 tag into the banner's middle. We also used a random background image to make the project look a bit aesthetic. We did some basic styling like font-family and size for the h1 tag to make the text look larger. After that, We styled the content and the button, which we will use to create the scroll-to-top button animation. We separately styled an active class for the 'scrollUp' button, which will trigger when the user scrolls down. That means when the 'pageYOffest' is above 100, this active class will trigger or appear; otherwise, it will remove the active. For a smooth transition, We have used CSS 'scroll-behavior: smooth' so that whenever someone clicks on the button, it slowly goes to the top of the page.
Scroll To Top Button using HTML CSS Jquery [ Source Code ]:
To create this project, you have to create HTML and CSS files. You can create a separate JS file if you want for putting the js code we used here. After that, copy the code from the code boxes below. Then paste it into your files, and save. Run the project to your browser and play around with the code. For the direct download, click the download button at the bottom of this blog post.
ADD HTML:
ADD CSS:
We hope you have got the snippet. For more snippets, please click the load more button on our website. Please follow our social media profiles to stay connected with this blog. Thank you for visiting the website.
Post a Comment
Please do not enter any spam link in the comment box.