【发布时间】:2023-03-10 05:31:01
【问题描述】:
当用户滚动到其子菜单的底部时,以下代码会导致左上方的菜单块滚动到视图中。
我遇到的问题是将菜单滚动到视图中后将其更改为 FIXED。目前,它继续在每次滚动时以动画形式出现在视图中。
在这里提琴:http://jsfiddle.net/GregsFiddle/rUsRz/
JS 下面:
jQuery( document ).ready( function( jQuery ) {
if ($("#autofixmenu")[0]){
var $autofixmenu = $("#autofixmenu"),
$bottom = $('#categories'),
$window = $(document),
offsetbtm = $bottom.offset(),
offset = $autofixmenu.offset(),
topPadding = 70;
$window.scroll(function() {
if ($window.scrollTop() > $autofixmenu.height() ) {
$autofixmenu.stop().addClass('autofixed').animate({
marginTop: $window.scrollTop() - offset.top + topPadding
});
} else {
$autofixmenu.stop().removeClass('autofixed').animate({
marginTop: 0
});
}
});
}
});
【问题讨论】:
-
检查这个小提琴jsfiddle.net/xATBt这是预期的行为吗?
-
几乎,我没有看到第一个菜单被动画化。如果我快速向下滚动,我希望菜单延迟滚动到视图中,然后变为固定。
-
我已经更新了小提琴。你能再检查一下吗?
-
我将在我的实时站点上对其进行测试,但蓝色框似乎与红色框一起向下滚动。我只希望红色向下滚动。
-
我自己也发布了一个答案。看看,告诉我你的想法。您共享的代码出于某种原因将错误的框放下。但我非常感谢您的帮助
标签: javascript jquery html jquery-animate