좋아요. 그래서 제가 예제를 만들었습니다. 나는 이것이 당신이 찾고 있던 무슨 희망 :
http://jsfiddle.net/gpcasx24/3/
자바 스크립트의 다음 조각 검사 (jQuery를 필요) 할 때 사용자가이 무엇인지 섹션 새로운 섹션과 수표를 입력 scrollspy 사항. 섹션의 이름을 추출하고 배열을 ColorForSection
에서 정의 할 수 있습니다.
// Change this to define your colors. Can also be rgb(0,0,0) etc
var ColorForSection = {
'#moose': '#ff0000',
'#bear': "#00ff00",
'#beaver': "#0000ff",
'#raccoon': "#ffff00",
'#bobcat': "#00ffff",
}
// Change the navbar's link color to a defined one based on the active nav link
function ChangeNavColor() {
// Get the section name from the navbar' now active URL
var currentSection = $(".nav li.active > a").attr('href');
// Set the link color
$(".nav a:link").css('color', ColorForSection[currentSection]);
}
// When scrollspy activates a new section, execute the ChangeNavColor function
$(document).on('activate.bs.scrollspy', ChangeNavColor);
// Call the function when the navbar's done loading
// So we also have the correct color to begin with.
$('.nav').ready(ChangeNavColor);
귀하의 링크의 href가이 #blabla
가 아닌 경우, 지금 날 수 있도록 내가 코드를 변경할 수 있습니다!
사용이 코드 조각 : :이 toggleClass는 다음과 같이 작동
// Execute the function when the page is scrolled
$(document).scroll(function() {
// Get the navbar
var nav = $('nav');
// Enable the class 'hidden' if scrollTop is lower or equal to 2
nav.toggleClass('hidden', $(document).scrollTop() <= 2);
});
때 페이지 상단
는 메뉴 바 숨기기. 두 번째 매개 변수에서 true
또는 false
으로 표시되는 '숨김'및 표시 여부를 알 수 있습니다.
$(document).scrollTop() <= 2
스크롤 량이 2 픽셀 미만인지 확인합니다. 절대 상단에 숨기려면이 값을 0으로 변경하면됩니다.
섹션의 높이를 2로 변경하십시오. 시도
다음 :
특정 섹션에 대한 메뉴 바 숨기기
// Sections to hide the nav in
var HideNavInSections = [
'#moose'
];
// Hide nav for specified sections
function HideNavOnScroll() {
// Get the section name from the navbar' now active URL
var currentSection = $(".nav li.active > a").attr('href');
// Should we hide the nav in this section?
$('.nav').toggleClass('hidden', HideNavInSections.indexOf(currentSection) != -1);
}
// When scrollspy activates a new section, execute the HideNavOnScroll function
$(document).on('activate.bs.scrollspy', HideNavOnScroll);
, 당신은 우리에게 코드를 줄 수주십시오? –
안녕하세요 @ FabianSierra 당신의 시간을 많이 tks! 당연하지! 지금 Jsdfiddle을 작성하고 있습니다. 그러나 간단한 코드 (기본 부트 스트랩 예제)를 사용하고 있습니다. – DANIEL
각 섹션에 고유 한 클래스 이름을 지정하고 해당 섹션의 배경색을 기반으로 글꼴 색상을 추가하십시오. – Gaurravs