0
나는이 코드를 작동하는 한 페이지 스크롤 사이트에서이 코드를 사용하고 있지만이 코드를 사용하는 대신 "href ="index.php # home "과 같은 href에 전체 URL을 추가했습니다. .. 해시 이제 내 활성 상태는 작동하려면이 코드를 수정할 수있는 방법 작동하지 않는탐색 스크롤 강조 표시
//Navigation Scroll/Highlight
var aChildren = $(".nav li.link").children();
var aArray = [];
for (var i=0; i < aChildren.length; i++) {
var aChild = aChildren[i];
var ahref = $(aChild).attr('href');
aArray.push(ahref);
}
$(window).scroll(function(){
var windowPos = $(window).scrollTop() + 140; // get the offset of the window from the top of page
var windowHeight = $(window).height(); // get the height of the window
var docHeight = $(document).height();
for (var i=0; i < aArray.length; i++) {
var theID = aArray[i];
var divPos = $(theID).offset().top; // get the offset of the div from the top of page
var divHeight = $(theID).height(); // get the height of the div in question
if (windowPos >= divPos && windowPos < (divPos + divHeight)) {
$("a[href='" + theID + "']").addClass("nav-active");
} else {
$("a[href='" + theID + "']").removeClass("nav-active");
}
}
if((windowPos + windowHeight) >= (docHeight - 140)) {
if (!$(".nav li.link:nth-last-child(2) a").hasClass("nav-active")) {
var navActiveCurrent = $(".nav-active").attr("href");
$("a[href='" + navActiveCurrent + "']").removeClass("nav-active");
$(".nav li.link:nth-last-child(2) a").addClass("nav-active");
}
}
});
코드에서 주석을 깨고 더 나은 것 모든 코드를 하나의 큰 섹션에 모아 둘 필요가 없으므로 여러 부분으로 나눌 수 있습니다. – Madness