2014-02-05 4 views
0

사용자가 전체 창 높이를 스크롤하기 전에 실행을 중지하려고하지만 콘솔에 표시되는 내용이 합산되지 않습니다. 어떻게 든 scrollHeight (scrollTop 값)는 윈도우 자체의 높이보다 더 커지게됩니다. 이것이 어떻게 가능한지?스크롤 높이가 창 높이보다 큰 이유는 무엇입니까?

$(document).ready(function() { 

    var windowHeight = $(window).height(); 

    if($(window).width() > 720 && $(window).scrollTop() < (windowHeight-400)) { 

       $(window).bind('scroll', function(){ 

       var scrollHeight = $(window).scrollTop(); 
       console.log('scroll height', scrollHeight) 
       console.log('window height', windowHeight) 

       function parallaxScroll(){ 
        $('#main').css('top',(500-(scrollHeight*2))+'px'); 
       }; 

        parallaxScroll(); 
       }); 
    } 
}); 

답변

2

당신은보기에 무엇이지고 있음을 의미 뷰포트의 높이를지고의 documentation from jQuery에서 찾고있다. 다음과 같이 높이를 문서 높이로 설정해야합니다.

$(document).ready(function() { 

    var windowHeight = $(document).height(); 

    if($(window).width() > 720 && $(window).scrollTop() < (windowHeight-400)) { 

       $(window).bind('scroll', function(){ 

       var scrollHeight = $(window).scrollTop(); 
       console.log('scroll height', scrollHeight) 
       console.log('window height', windowHeight) 

       function parallaxScroll(){ 
        $('#main').css('top',(500-(scrollHeight*2))+'px'); 
       }; 

        parallaxScroll(); 
       }); 
    } 
}); 
관련 문제