繁体   English   中英

Jquery检测div滚动条滚动到顶部

[英]Jquery detect div scroll bar scroll to top

var Height = 600;

    $('#message_container').scroll(function(){
        if ($('#message_container').scrollTop() > Height){
            alert('up');

        }else{
            alert('down');
        }
    });

我有div overflow-y:auto ,它每次都会获取10条消息。

我尝试使用jquery向上滚动来获取更多消息。

div高度为600px; 我正在测试, 即使我向上滚动它也会保持警惕 ,任何人都知道为什么?

这是小提琴http://jsfiddle.net/asEmz/

来自JQuery

垂直滚动位置与可滚动区域上方的视图中隐藏的像素数相同。 如果滚动条位于最顶部,或者元素不可滚动,则此数字将为0

所以用0 演示测试

$(document).ready(function(){           
    $("#message_container").scrollTop($("#message_container")[0].scrollHeight);

    var Height = 600;

    $('#message_container').scroll(function(){
        if ($('#message_container').scrollTop() == 0){
            $('#status').html('up');
            //alert('up');

        }else{
            $('#status').html('down');
            //alert('down');
        }
    });

});
$(document).ready(function(){           
$("#message_container").scrollTop($("#message_container")[0].scrollHeight);

var Height = 60;

$('#message_container').scroll(function(){
    if ($('#message_container').scrollTop() < Height){
        alert('up');

    }else{
        alert('down');
    }
});

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM