So I have a simple button that hovers at the bottom of the screen that when click it scrolls back to the top of the page. The problem is when click the button begins to fade out, then back in, and then back out once it gets to the top.
Here is my code:
<div class="backToTop">
<a href="#top">Top</a>
</div>
Javascript:
$(window).scroll(function () {
if ($(window).scrollTop() > $(this).height() + 100) {
$('.backToTop').fadeIn();
} else {
$('.backToTop').fadeOut();
}
});
$('.backToTop a').click(function () {
var anchor = $(this).attr('href');
var sub = anchor.substring(anchor.search('#'));
$('html, body').animate({ scrollTop: 0 }, 800);
});