[英]Fade in/out div scrollTop
I have a floating menu that i want to fade in when you start to scroll down the page, then fade out when you are back at the top of the page. 我有一个浮动菜单,我想在您开始向下滚动页面时淡入,然后在您回到页面顶部时淡出。 I have got it working without the fade, but im not sure how to add the fades.
我没有褪色,但我不确定如何添加褪色。 Any help appreciated.
任何帮助表示赞赏。 Thanks.
谢谢。
$(document).scroll(function() {
$('#floatingnav').toggle($(this).scrollTop()>250)
});
css 的CSS
#floatingnav {
position:fixed;
display:none;
}
You can use fadeToggle with some duration as an argument(just incase you want) instead of plane toggle.That will do your job. 您可以使用带有一定持续时间的fadeToggle作为参数(以防万一),而不是使用平面切换。
$(document).scroll(function() {
$('#floatingnav').fadeToggle($(this).scrollTop()>250)
});
You can try this to test if div
has reached top 您可以尝试测试
div
是否达到顶部
$(window).scroll(function () {
var d = $('div'); // this is your fixed div
if (d.offset().top > 250) {
d.fadeIn();
} else {
d.stop().fadeOut();
}
});
$(window).bind("scroll", function() {
if ($(this).scrollTop() > 250) {
$("#floatingnav").fadeIn();
} else {
$("#floatingnav").stop().fadeOut();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.