3

如何检测div滚动条何时向上滚动并击中顶部(仅当它击中顶部时)

我找到了另一篇文章,但这篇文章被击中了底部。

我需要的是达到顶峰。有谁知道如何改变这个?

$("#divID").scroll(function(){
    if($(this)[0].scrollHeight - $(this).scrollTop() <= $(this).outerHeight())
    {
        alert(1);
    }
});

知道垂直滚动条何时到达 div 中的滚动底部

4

3 回答 3

4

工作小提琴

var el = $('.test');
el.on('scroll', function(){

    if(el.scrollTop() == 0){alert("i just hit the top")}


});
于 2013-07-30T12:09:51.923 回答
1

scrollTop0在滚动条位于顶部时。尝试这个:

$("#divID").scroll(function () {
    if ($(this).scrollTop() == 0) {
        alert(1);
    }
});

示例小提琴

于 2013-07-30T12:09:38.523 回答
0
$("#divID").scroll(function(){
    if($(this)[0].scrollHeight - $(this).scrollTop() <= $(this).outerHeight())
    {
        alert("Bottom");
    }
    if($(this).scrollTop() == 0)
    {
        alert("Top");
    }
});

小提琴在这里

于 2013-07-30T12:12:44.310 回答