我希望当用户到达 div#btm 时,它会淡出。我知道如何做CSS部分,只需添加过渡和不透明度0。但是如何使用scrollTop来检查用户是否滚动到该元素?
我不想使用outerHeight,因为我的元素并不完全位于窗口的底部。
最佳答案
按照以下代码片段操作
您可以使用一些属性/方法:
$().scrollTop()//how much has been scrolled
$().innerHeight()// inner height of the element
DOMElement.scrollHeight//height of the content of the element
因此,您可以取前两个属性的总和,当它等于最后一个属性时,您就到达了结尾:
jQuery(function($) {
$('#flux').bind('scroll', function() {
if($(this).scrollTop() + $(this).innerHeight() >= this.scrollHeight) {
alert('end reached');
}
})
});
或
$(document).ready(function() {
$('#btm').bind('scroll', function()
{
if($(this).scrollTop() + $(this).innerHeight() >= this.scrollHeight)
{
alert('end reached');
}
});
});
关于javascript - scrollTop 检查用户是否滚动到某个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25281919/