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


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; 在 IM 测试时,即使我向上滚动,它也会保持警惕,有人知道为什么吗?

这是小提琴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');
    }
});
});

最新更新