[英]Detect div scroll bar hit the top
如何检测div滚动条何时向上滚动并到达顶部(仅当它到达顶部时)
我发现了另一篇文章,但这篇文章已触底。
我需要的是击中顶部。 有人知道如何改变吗?
$("#divID").scroll(function(){
if($(this)[0].scrollHeight - $(this).scrollTop() <= $(this).outerHeight())
{
alert(1);
}
});
var el = $('.test');
el.on('scroll', function(){
if(el.scrollTop() == 0){alert("i just hit the top")}
});
当滚动条位于顶部时, scrollTop
将为0
。 尝试这个:
$("#divID").scroll(function () {
if ($(this).scrollTop() == 0) {
alert(1);
}
});
$("#divID").scroll(function(){
if($(this)[0].scrollHeight - $(this).scrollTop() <= $(this).outerHeight())
{
alert("Bottom");
}
if($(this).scrollTop() == 0)
{
alert("Top");
}
});
小提琴在这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.