This is how I include the button in the body:
<?php require_once('scrollToTop.php'); ?>
This is my scroll tTo Top.php file:
<div class="btnScrollToTop" data-scroll="up" type="button">
<img src="images/paudie_scroll_top_icon.jpg" alt="">
This is the CSS for the button:
.btnScrollToTop {
position: fixed;
right: 20px;
bottom: 20px;
width: 50px;
width: 50px;
border: none;
z-index: 99;
}
This is my js file included in php footer as:
<script src="js/scroll.js"></script>
// JavaScript Document
const btnScrollToTop = document.querySelector(".btnScrollToTop");
btnScrollToTop.addEventListener("click", function() {
window.scrollTo({
top: 0,
left: 0,
behavior: "smooth"
});
});
I am unable after a variety of attempts to get he button to appear only one the use has scroll 20px from the top of page.
Please help.