I am using the code below in my < head > tags to create a button that fades in when the window is 150px from the bottom.
<script>
$(window).scroll(function () {
if ($(window).scrollTop() + $(window).height() > ($(document).height() - 150)) {
$("#up-btn").fadeIn(500);
} else {
$("#up-btn").fadeOut(500);
}
});
</script>
Here is the CSS code:
#up-btn {
position: fixed;
display: none;
font-size: 1em;
font-weight: 700;
letter-spacing: 2px;
text-transform: uppercase;
bottom: -4px; right: 3%;
color: #fff;
border-radius: 2px;
background-color: #1aa97f;
padding: 18px 20px; margin: 25px auto 0 auto;
}
And here is the HTML code:
<footer>
<a id="up-btn" href="javascript:void(0);" onclick="scrolltop();">TOP <i class="fa fa-chevron-up"></i></a>
</footer>
My goal is to make sure that the #up-btn remains hidden on mobile devices.