Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 将Div滚动到底部时从服务器加载数据_Jquery_Javascript - Fatal编程技术网

Jquery 将Div滚动到底部时从服务器加载数据

Jquery 将Div滚动到底部时从服务器加载数据,jquery,javascript,Jquery,Javascript,只有当我通过滚动到达div底部附近时,我才需要在div中加载数据 我面临的问题是$('div').scrollHeight()和$('div').scrollTop()的值在到达底部时不相同,因此我无法确定滚动是否到达底部 如何识别div滚动条已到达底部附近(或者可能是底部减去某个长度) 请建议 注意:基本上,我也在尝试做类似于Facebook ticker的事情 问候,, Navin有一个JSFIDLE,它使用scrollTop+clientHeight与scrollHeight进行比较。看看

只有当我通过滚动到达div底部附近时,我才需要在div中加载数据

我面临的问题是$('div').scrollHeight()和$('div').scrollTop()的值在到达底部时不相同,因此我无法确定滚动是否到达底部

如何识别div滚动条已到达底部附近(或者可能是底部减去某个长度)

请建议

注意:基本上,我也在尝试做类似于Facebook ticker的事情

问候,, Navin有一个JSFIDLE,它使用scrollTop+clientHeight与scrollHeight进行比较。看看这是否适用于你,抱歉,这是在Mootools中,但它非常简单

function HandleScroll()
{
    var el = $("outer");
    if( (el.scrollTop + el.clientHeight) >= el.scrollHeight )
    {
        el.setStyles( { "background-color": "red"} );
    }
    else
    {
        el.setStyles( { "background-color": "white"} );
    }
}

网上有很多滚动条示例,下面的代码来自


希望能有所帮助。

我建议您获取文档高度,并使用该高度作为页面顶部到底部之间的长度。因此:

var bottom = $(document).height() // == the bottom of your page
你可以减去你想要的底部的距离

If( ( el.scrollTop() + el.outherHeight ) >= ( bottom - 200 ) ){
    // fetch new data

    // Don't forget to upate the bottom variable when data fetched and renderd
}
希望这能解决你的问题,或者至少能帮助你找到解决方案。如果没有,请告诉我

If( ( el.scrollTop() + el.outherHeight ) >= ( bottom - 200 ) ){
    // fetch new data

    // Don't forget to upate the bottom variable when data fetched and renderd
}