【发布时间】:2015-11-03 11:20:05
【问题描述】:
我已经构建了一个菜单,当您从顶部向下滚动超过 250 像素时,它会折叠并在您返回顶部时返回其原始状态。但是我的网站有一些链接到主页中间的锚链接。当我直接转到这些链接时,菜单不起作用。我必须先滚动。他们有办法解决这个问题吗?
这是我使用的代码:
<script>
jQuery(function () {
jQuery('.fixed').data('size', 'big');
});
jQuery(window).scroll(function () {
if (jQuery(window).scrollTop() > 250) {
if (jQuery('.fixed').data('size') == 'big') {
jQuery('.fixed').data('size', 'small');
jQuery('.fixed').stop().animate({
top: '-125px'
}, 600);
jQuery('.navbar-nav').stop().animate({
top: '15px'
}, 600);
jQuery('.dmbs-header-img').stop().animate({
opacity: '0'
}, 200);
jQuery('.logo-simple').stop().delay(200).animate({
top: '120px'
}, 600);
}
} else {
if (jQuery('.fixed').data('size') == 'small') {
jQuery('.fixed').data('size', 'big');
jQuery('.fixed').stop().animate({
top: '0px'
}, 200);
jQuery('.navbar-nav').stop().animate({
top: '0px'
}, 200);
jQuery('.dmbs-header-img').stop().animate({
opacity: '1'
}, 100);
jQuery('.logo-simple').stop().animate({
top: '-50px'
}, 200);
}
}
});
</script>
【问题讨论】:
-
能否添加一个 jsfiddle 帮助我们更轻松地找到解决方案?
标签: javascript jquery html menu collapse