Is there a way to hide the button with the id #stats while the user is scrolling, and then have it fade back in once they finish scrolling?
It seems like the code below is not working as expected.
Any help would be greatly appreciated!
<button id="stats">
<span class="icon prs"></span><h3 id="views" class="prm">@file.views</h3>
<span class="icon prs"></span><h3 id="comments">20</h3>
</button><!--end stats-->
<script>
$(function(){
$('#stats').hide().fadeIn('slow');
});
var $stats = $("#stats");
var opacity = $stats.css("opacity");
var scrollStopped;
var fadeInCallback = function () {
if (typeof scrollStopped != 'undefined') {
clearInterval(scrollStopped);
}
scrollStopped = setTimeout(function () {
$stats.animate({ opacity: 1 }, "slow");
}, 200);
};
$(window).scroll(function () {
if (!$stats.is(":animated") && opacity == 1) {
$stats.animate({ opacity: 0 }, "slow", fadeInCallback);
} else {
fadeInCallback.call(this);
}
});
</script>