Reputation: 3960
This is what I'm trying to do:
div
when .scrollTop() > 20
fadeOut
after delayfadeOut
when :hover
the sticky footerThis is my jquery:
$(function () {
var targets = $(".footer-nav");
if ($(window).scrollTop() > 20) {
$(this).addClass('show');
}
$(window).scroll(function () {
var pos = $(window).scrollTop();
if (pos > 10) {
targets.stop(true, true).fadeIn("fast").delay(2000).fadeOut(2000);
} else {
targets.stop(true, true).fadeOut();
}
});
});
I'm having problems with point .3. Also, when I move the scroll wheel really fast the sticky footer flickers. Is there a way to optimize/improve. Jsfiddle here. Thanks.
Upvotes: 4
Views: 8533
Reputation: 5810
I guess this is exactly what you looking for:
JQuery
$(window).scroll(function(event) {
function footer()
{
var scroll = $(window).scrollTop();
if(scroll>20)
{
$(".footer-nav").fadeIn("slow").addClass("show");
}
else
{
$(".footer-nav").fadeOut("slow").removeClass("show");
}
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(function() {
if ($('.footer-nav').is(':hover')) {
footer();
}
else
{
$(".footer-nav").fadeOut("slow");
}
}, 2000));
}
footer();
});
Upvotes: 3
Reputation: 4742
Register a mouseover function to stop the fading animation and fade it back in quickly. Also, within that handler, register a mouseout handler, which fades it out and then deregisters itself.
$('.footer-nav').on('mouseover', function () {
$(this).stop().fadeTo(100, 1);
$(this).on('mouseout', function () {
$(this).stop().fadeOut(2000);
$(this).off('mouseout');
});
});
The previous answer does not register a mouseout event so that the footer fades out when the cursor leaves.
Upvotes: 1