I'm trying to implement a simple "scroll to top" button on my site.
HTML:
<a href="#" id="scrolltotop"><img src="img/scrolltotop.png"></a>
CSS:
#scrolltotop {
width: 40px;
height: 40px;
position: fixed;
right: 100px;
bottom: 50px;
display: block;
}
JS:
jQuery(document).ready(function($){
$(window).scroll(function(){
if ($(this).scrollTop() > 150) {
$('#scrolltotop').fadeIn('slow');
} else {
$('#scrolltotop').fadeOut('slow');
}
});
$('#scrolltotop').click(function(){
$("html, body").animate({ scrollTop: 0 }, 500);
return false;
});
});
When I load my page, I see the button there in the right place for a split second, then it is covered by a background of one of my divs that is down the page in my HTML structure. In the end, I can't see it anywhere on my page, and when I inspect the element it is in the right spot, just not visible.
divyou talk about is in. And the CSS for thatdiv? It might indeed like an answer says be thez-indexbut it could be something else. Are you sure you are not scrolling down and the#scrolltotopgets faded out?