Jquery 滚动高度如何大于窗口高度?

Jquery 滚动高度如何大于窗口高度?,jquery,Jquery,我试图让一个函数在用户滚动整个窗口高度之前停止运行,但我在控制台中看到的结果并不正确。不知何故,scrollHeight(scrollTop值)最终超过了窗口本身的高度。这怎么可能 $(document).ready(function() { var windowHeight = $(window).height(); if( $(window).width() > 720 && $(window).scrollTop() < (windowHe

我试图让一个函数在用户滚动整个窗口高度之前停止运行,但我在控制台中看到的结果并不正确。不知何故,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();
                });
    }
});
$(文档).ready(函数(){
var windowHeight=$(window.height();
if($(window.width()>720&&$(window.scrollTop()<(windowHeight-400)){
$(窗口).bind('scroll',function(){
var scrollHeight=$(窗口).scrollTop();
console.log('滚动高度',滚动高度)
console.log('窗高',窗高)
函数视差croll(){
$('#main').css('top',(500-(scrollHeight*2))+'px');
};
视差克罗尔();
});
}
});
查看,您得到的是视口的高度,这意味着您只得到视图中的内容。您需要将高度设置为文档高度,如下所示:

$(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();
                });
    }
});
$(文档).ready(函数(){
var windowHeight=$(document.height();
if($(window.width()>720&&$(window.scrollTop()<(windowHeight-400)){
$(窗口).bind('scroll',function(){
var scrollHeight=$(窗口).scrollTop();
console.log('滚动高度',滚动高度)
console.log('窗高',窗高)
函数视差croll(){
$('#main').css('top',(500-(scrollHeight*2))+'px');
};
视差克罗尔();
});
}
});