Explaining the HTML
The button is constructed from an <a>
element with the following parameters:
btn btn-primary rounded-circle
classes to provide shape and colorbtn-back-to-top
class for positioningdata-smooth-scroll
attribute to handle animating scroll to top of pagedata-aos="fade-up"
to handle hide/show of the button and provide subtle animationdata-aos-offset="2000"
shows the button after the user scrolls 2000 pixels down the page. This works because the element isposition: fixed
so its original place is within the initial viewport. Settingdata-aos-offset
to 2000 pixels causes the button to be shown when the user scrolls 2000 pixels past the element's naturally visible location.data-aos-mirror="true"
anddata-aos-once="false"
ensures that the button will animate out again when the user scrolls back up
Inside the <a>
element is an <img>
with class icon bg-white
for size and color. data-inject-svg
allows us to color the SVG through CSS classes.
<a href="#top" class="btn btn-primary rounded-circle btn-back-to-top" data-smooth-scroll data-aos="fade-up" data-aos-offset="2000" data-aos-mirror="true" data-aos-once="false">
<img src="assets/img/icons/interface/icon-arrow-up.svg" alt="Icon" class="icon bg-white" data-inject-svg>
</a>