특정 높이로 고정되는 navbar가 있습니다 (원래 navbar-container를 복제하고 스크롤 한 후 복제본 만 표시).다른 스크롤 기능 내에서 스크롤 할 때 div 표시/숨기기
사용자가 아래로 스크롤 할 때마다 숨기고 싶은 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');
}
});
여기 올바른 길에 있습니까? 광고와 툴바는 모두 플렉스 박스입니다. 탐색 표시 줄의 링크에 마우스를 올리면 드롭 다운 메뉴가 표시됩니다 (위도 좋음). 그냥 nav 광고를 알아낼 수 없습니다!
@bibs이 도움이됩니다. –