I use Google Chrome 10 and write JavaScript to detect the end of the scroll.
To detect the end of the scroll window, the code below worked fine:
window.addEventListener(
'scroll',
function()
{
var scrollTop = document.documentElement.scrollTop ||
document.body.scrollTop;
var offerHeight = document.body.offsetHeight;
var clientHeight = document.documentElement.clientHeight;
if (offsetHeight <= scrollTop + clientHeight)
{
}
},
false
);
Now I want to detect the end of the scroll of the specified element, for example <section id="box" style="height: 500px; overflow: auto;">
This is code that is not detected correctly:
document.getElementById('box').addEventListener(
'scroll',
function()
{
var scrollTop = document.getElementById('box').scrollTop;
var offerHeight = document.getElementById('box').offsetHeight;
var clientHeight = document.getElementById('box').clientHeight;
if (offsetHeight <= scrollTop + clientHeight)
{
}
},
false
);
Can someone fix my code? Thank.
source
share