I am currently using code that displays a scroll to top button.
$(window).bind("scroll", function() {
if ($(this).scrollTop() > 100) {
$("#totop").fadeIn();
} else {
$("#totop").stop().fadeOut();
}
The opacity of this div is set to 0.8. However, I have noticed that when I repeatedly scroll up and down, the div slowly fades out. This seems to be due to the opacity compounding on itself (0.8 of 0.8 and so on).
Is there a way to prevent this from happening?