내가 .bullseye 당신이 섹션 (#home, # 정보, #portfolio, #contact)에 추가해야하는 클래스입니다 스크롤 기능
// On Scroll Change Nav
jQuery('.bullseye').waypoint(function(direction) {
var idThis = jQuery(this).attr('id');
if(direction === 'down'){
jQuery('a.scroll').removeClass('active');
jQuery('a[href="#'+idThis+'"]').addClass('active');
//console.log(idThis);
}
}, { offset: 75 });
jQuery('.bullseye').waypoint(function(direction) {
var idThis = jQuery(this).attr('id');
if(direction === 'up'){
jQuery('a.scroll').removeClass('active');
jQuery('a[href="#'+idThis+'"]').addClass('active');
//console.log(idThis);
}
}, { offset: 'bottom-in-view' });
에 대한 웨이 포인트 http://imakewebthings.com/jquery-waypoints/를 사용하여 비슷한 만들었습니다. 다음
그리고
메뉴 모음에 대한
// Smooth Scroll
jQuery('a.scroll[href*=#]:not([href=#])').click(function() {
jQuery('a.scroll').removeClass('active');
var hrefMatch = jQuery(this).attr('href');
jQuery('a[href="'+hrefMatch+'"]').addClass('active');
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
|| location.hostname == this.hostname) {
var target = jQuery(this.hash);
target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']');
if (target.length) {
jQuery('html,body').animate({
scrollTop: target.offset().top - 75
}, 1000);
return false;
}
}
});
그리고 마지막 아니지만 적어도를 (당신이 메뉴 링크에 .scroll 클래스를 추가하거나 스크립트를 개조 할 필요)에서 클릭 이벤트에 대한 스크립트 활성 클래스는
.menu a.active{
color: #fff;
background-color: black;
padding: 5px;
}
작동합니다 그리고 기본적으로 그것 뿐이다 :) 당신이 :)이
난 당신이 라우팅을위한 해시 태그를 활용 참조 왜 당신의 메뉴 배경을 설정뿐만 아니라 것을 사용할 수 없습니다. – Daniel
자바 스크립트로 클래스를 추가하는 것은 어떨까요? –
질문에 관련 코드를 게시하십시오 ([최소, 완전하고 검증 가능한 예제] (http://stackoverflow.com/help/mcve/)를 만드십시오). 귀하의 사이트에 링크 만하지 마십시오 (귀하의 문제가 해결되면 이후의 모든 사람들에게 그 의문이 무의미 해지기 때문에). –