The following code, will make the “Go to top” button fade in when the scrollTop() is over 400px, that works fine, but i haven’t found a way to make it fade out when i go back to the top.
$("#gototop").css("opacity", "0");
$(window).bind('scroll', function(){
if($(this).scrollTop() > 400) {
$("#gototop").animate({
opacity: 100,
}, 3400);
}
});
An else after the if didn’t help, i tried different options with my non-ninja skills but none worked. Any ideas on how to make it fade out when the scroll is back at the top?
Thanks.
I ended up using a plugin called waypoints to handle the scroll position.