javascript: detect scroll end

Zebra picture Zebra · Oct 18, 2010 · Viewed 96k times · Source

I have a div layer with overflow set to scroll.

When scrolled to the bottom of the div, I wanna run a function.


Answer

Bjorn picture Bjorn · Jan 9, 2011

The accepted answer was fundamentally flawed, it has since been deleted. The correct answer is:

function scrolled(e) {
  if (myDiv.offsetHeight + myDiv.scrollTop >= myDiv.scrollHeight) {
    scrolledToBottom(e);
  }
}

Tested this in Firefox, Chrome and Opera. It works.