2014-02-19 3 views
0

뭔가 잘못 정의되어있어 제대로 작동하지 않습니다. 나는 내가 뭔가 잘못하고 있다고 생각하지만, 나는 무엇을 알아낼 수 없다. 당신이 실제로 기능의 3에서 계산 된 값을 반환하지 않는 것 같은스크롤을 사용하여 섹션 변경시 해시 변경

//change the window hash 
var changeHash = function(a) { 
    document.location.hash = a 
}; 
//get the scrollPos 
var scrollPos = function(){ 
    $(window).scrollTop() 
}; 
//find the position of the top of element 
var topPos = function(a){ 
    $(a).offset().top 
}; 
//find the position of the bottom of element 
var bottomPos = function(a){ 
    $(a).offset().top + $(a).height() 
}; 

$(window).scroll(function() { 
    if ($(this).scrollTop() < bottomPos('#top')) { 
     $('.navbar').fadeOut('fast'); 
     changeHash(''); 
    } 
    else { 
     $('.navbar').fadeIn('fast'); 
     return; 

     if(scrollPos <= topPos('#services') && scrollPos >= bottomPos('#services')){ 
      changeHash('services'); 
     } 
     if(scrollPos <= topPos('#work') && scrollPos >= bottomPos('#work')){ 
      changeHash('work'); 
     } 
     if(scrollPos <= topPos('#connect') && scrollPos >= bottomPos('#connect')){ 
      changeHash('connect'); 
     } 
    } 
}); 

답변

0

는 것 같습니다.

//get the scrollPos 
var scrollPos = function(){ 
    return $(window).scrollTop(); 
}; 
//find the position of the top of element 
var topPos = function(a){ 
    return $(a).offset().top; 
}; 
//find the position of the bottom of element 
var bottomPos = function(a){ 
    return $(a).offset().top + $(a).height(); 
}; 

사이드 참고 :이 시도 당신은 window에서 return의 타고 도착 할 수 있습니다 - scroll - else 문을?