Reputation: 13923
Is it possible to determine when a dom element has come into view ?
I would like an event to be raised when an element (e.g div, image) has come into the view of the browser
Is this possible ?
Upvotes: 0
Views: 304
Reputation: 1046
I don't see an "easy" way to do it. You basically would have to attach a check to the scroll and resize events. You'll need to do all the calculations - height of window, how much it was scrolled, element's offset, and using these you can see if the element has been scrolled to. Couple of potential optimizations would be - only recheck window height on resize, make sure the element has an ID so it's a quick lookup, use a flag if what you want to do is a one time thing, i.e. once it becomes visible and you do what you do stop the checks.
Upvotes: 1
Reputation: 17898
Where I saw this question? Right, here.
Not exactly the same but might help.
Upvotes: 3
Reputation: 382606
I would like an event to be raised when an element (e.g div, image) has come into the view of the browser
You can use the onload
event for that which fires when all images, DOM, frames have loaded into the page :)
Upvotes: 0