views:

46

answers:

1
+2  A: 

If it were me, here is what I would do:

add an event handler to the scroll event (any time there is a scroll, this function will be called).

function scrolled(e) {
    var evt = e || window.event;
    if (myDiv.offsetHeight - evt.scrollTop === 0) {
        //call function - myDiv scrolled to the bottom
        scrolledToBottom(e);
    }
}
Gabriel McAdams
Isn't "scrollTop" supposed to give the number of pixels that are actually scrolled out of the scroll area? In other words, I think you have to subtract the scrolled box's height from the height of the stuff being scrolled. I could be wrong however; I've never tried to do this particular thing.
Pointy
@Pointy: You're right. I modified my answer to reflect this.
Gabriel McAdams
@Gabrel McAdams: thanks, what do I pass as 'e' and could you rewrite the syntax as if myDiv were $('#myDiv')?
dany
`e` is the event. When you assign the event handler, depending on the browser, e will either be passed in (or as in IE, will be available through the event property of the window object). This is why I have the first line to make sure we get the event, wherever it may be.
Gabriel McAdams
In my example, I am assuming you already have a reference to the div. If you get the reference by using `$(#myDiv)` then either add `var myDiv = $(#myDiv);` before you use the reference, or replace `myDiv` with `$(#myDiv)`
Gabriel McAdams
@Gabrel McAdams: thank you very much!
dany