我有一个固定在某个高度的导航栏(通过克隆原始导航栏容器并仅在滚动后显示克隆完成)。在另一个滚动功能中隐藏/显示滚动条div
此navbar-container(广告)中有一个div,我想在用户向下滚动时隐藏,并在向上滚动时再次出现。但是,我没有取得任何成功!
导航栏的基本HTML:
<div class="toolbar-container">
<div class="nav-ad"> ... </div>
<div class="toolbar"> link 1 • link 2 • link 3 ... </div>
</div>
我的代码不工作:
$(window).scroll(function() {
if ($(this).scrollTop()>0) {
$('.cloned.nav-ad').fadeOut();
} else {
$('.cloned.nav-ad').fadeIn();
}
});
的jQuery的导航栏克隆(一个很好的解决方案,从http://codepen.io/senff/pen/ayGvD以防止它跳跃):
$('.toolbar-container').addClass('original').clone().insertAfter('.toolbar-container').addClass('cloned').css('position','fixed').css('top','0').css('margin-top','0').css('z-index','500').removeClass('original').hide();
scrollIntervalID = setInterval(stickIt, 10);
function stickIt() {
var orgElementPos = $('.original').offset();
orgElementTop = orgElementPos.top;
if ($(window).scrollTop() >= (orgElementTop)) {
// scrolled past the original position; now only show the cloned, sticky element.
// Cloned element should always have same left position and width as original element.
orgElement = $('.original');
coordsOrgElement = orgElement.offset();
leftOrgElement = coordsOrgElement.left;
widthOrgElement = orgElement.css('width');
$('.cloned').css('left',leftOrgElement+'px').css('top',0).css('width', widthOrgElement).show();
$('.original').css('visibility','hidden');
} else {
// not scrolled past the menu; only show the original menu.
$('.cloned').hide();
$('.original').css('visibility','visible');
}
});
我在正确的轨道上吗?广告和工具栏都是flexbox。导航栏中的链接显示悬停下拉(这也很棒)。只是无法弄清楚导航广告!
@bibs这是否帮助你。 –