가 나는 경우의 수를 알고 싶습니다 어떤 요소를 볼 수 확인 : 순간에 볼 수 있습니다 ".main"JQuery와 + 스크롤 + jQuery를 다음을 수행하기로
-check 동적으로 ".active"를 "nav"의 해당 링크에 추가 하시겠습니까?
감사합니다.
편집 :
내가 사용하여 밖으로 일한이 Viewport Plugin 코드 다음 도움을
//find what element is in view
var inview = '#' + $('.sectionSelector:in-viewport:first').attr('id'),
//find the corresponding link
$link = $('.mainNav li a').filter('[hash=' + inview + ']');
//check i its already active or not and if not
if ($link.length && !$link.is('.active')) {
//remove all previous active links and make the current one active
$('.mainNav li a').removeClass('active');
$link.addClass('active');
}
//Start same proccess on every scroll event again
$(window).scroll(function() {
var inview = '#' + $('.sectionSelector:in-viewport:first').attr('id'),
$link = $('.mainNav li a').filter('[hash=' + inview + ']');
if ($link.length && !$link.is('.active')) {
$('.mainNav li a').removeClass('active');
$link.addClass('active');
}
});
감사 every1!
가능한 중복 (http://stackoverflow.com/questions/487073/check-if-element-is -visible-after-scroll) –