Seeking help with creating a scroll to top button that fades in when the user scrolls down.
I've successfully positioned the button and made it scroll to the top when clicked. However, the button remains visible at all times without any fading effects.
Here is my current setup:
HTML
<a class="scrollup" href="#">Scroll To Top</a>
This HTML code is placed within a paragraph inside a div element.
Javascript
<script type="text/javascript" src="../../../../jquery-1.11.0.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(window).scroll(function(){
if (jQuery(this).scrollTop() > 100) {
jQuery('.scrollup').fadeIn();
} else {
jQuery('.scrollup').fadeOut();
}
});
// scroll-to-top animate
jQuery('.scrollup').click(function(){
jQuery("html, body").animate({ scrollTop: 0 }, 600);
return false;
});
});
CSS
.scrollup {
height: 50px;
width: 50px;
opacity:1.0;
padding:10px;
text-align:center;
background: #FFFFFF;
font-weight:bold;
color:#444;
text-decoration:none;
position:fixed;
top:75px;
right:40px;
}
The issue I'm facing is that the button does not fade in as I scroll or fade out when I click on it to go to the top of the page.
Your assistance in resolving this matter would be greatly appreciated. Thank you.