0

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 ?

Prakash Raman
  • 13,319
  • 27
  • 82
  • 132
  • 1
    Do you mean an element that was below the fold? That the user has now scrolled to - hence it is unhidden by the browser chrome? – diagonalbatman Feb 17 '11 at 12:39

3 Answers3

3

Where I saw this question? Right, here.

Not exactly the same but might help.

Community
  • 1
  • 1
Jan Zyka
  • 17,460
  • 16
  • 70
  • 118
1

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.

Ilia Draznin
  • 1,026
  • 2
  • 12
  • 24
0

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 :)

Sarfraz
  • 377,238
  • 77
  • 533
  • 578