[英]Fixed top menu on scroll doesn't allow to reach screen's bottom
I have a strange behavior with my fixed top menu. 我的固定顶部菜单有异常行为。 The screen height is dynamic (depends on the number of registries retrived by the database).
屏幕高度是动态的(取决于数据库检索的注册表数)。 When the number of registries creates a scroll, but not high enough to cover up all the menu, the screen bounces and doesn't allow me to reach the bottom (the scroll jumps up again, no matter what).
当注册机构的数量创建了一个滚动条,但滚动条的高度不足以掩盖所有菜单时,屏幕会跳动,并且不允许我触底(滚动条会再次跳起,无论如何)。
I was able to simulate the behavior here: http://jsfiddle.net/thiagoprzy/0kkx9tsb/ 我可以在这里模拟行为: http : //jsfiddle.net/thiagoprzy/0kkx9tsb/
I believe the issue relies on the way I created the JS part, but when I searched about alternative solutions, almost all of them were very very similar to this one. 我认为问题取决于我创建JS部分的方式,但是当我搜索替代解决方案时,几乎所有解决方案都与此非常相似。
PS: My screen resolution is 1650x1050, so if you have a tinier resolution, maybe you'll need to change the .container
height value in order to reproduce the issue. PS:我的屏幕分辨率为1650x1050,因此,如果您具有较小的分辨率,则可能需要更改
.container
height值才能重现此问题。
you need to use $('.content').offset().top
instead of $('.floating-filter').offset().top
or you can use 您需要使用
$('.content').offset().top
而不是$('.floating-filter').offset().top
否则您可以使用
if ($(window).scrollTop() > $('.floating-filter').outerHeight(true)) {
So you can use 所以你可以使用
$(window).scroll(function () {
if ($(window).scrollTop() > $('.content').offset().top) {
$('.floating-filter').addClass('fixed');
} else {
$('.floating-filter').removeClass('fixed');
}
});
So, that's my solution: http://jsfiddle.net/thiagoprzy/0kkx9tsb/15/ 所以,这就是我的解决方案: http : //jsfiddle.net/thiagoprzy/0kkx9tsb/15/
Basically I gave up on position: fixed
and used position: absolute
. 基本上我放弃了
position: fixed
和used position: absolute
。 Then, I put the menu inside a wrapper with position: relative
and, in $(document).ready()
I set the wrapper's height the same as the menu. 然后,将菜单放在
position: relative
的包装器内,并在$(document).ready()
中将包装器的高度设置为与菜单相同。 For last, I update the top
value of the menu based on $(window).scrollTop()
position inside $(window).scroll()
event. 去年,我更新了
top
基于菜单的值$(window).scrollTop()
的位置内$(window).scroll()
事件。 Maybe it's not the most clean solution, but it solved my issue and now I'm happy. 也许这不是最干净的解决方案,但是它解决了我的问题,现在我很高兴。 =)
=)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.