10

I'm looking for a method to know if a object (as a Div, a img, etc.) is displayed and visible by the user at the window in JavaScript / jQuery.

When I say "is displayed and visible", that's when the user don't scroll the page enough to let's the object visible (If you know what I mean). But if the user scroll the page and the div is no longer visible (is out the window) the function what I'm looking for should know that.

halfer
  • 19,471
  • 17
  • 87
  • 173
Zachary Dahan
  • 1,369
  • 15
  • 26

1 Answers1

11

You should use Viewport selectors for jQuery to check if the element is currently visible in the actual viewport.

Here's a demo to show you what I mean.

dsgriffin
  • 64,660
  • 17
  • 133
  • 135
  • 5
    As someone came and trashed away a part of history, I would like to thank you again for this answer. Since those last 3 years, I still on SO thanks to people like you who treat any OP like a human being, even if their question was completely noob, duplicated, etc. etc. And this question has served to many people and keep being active after 3 years. – Zachary Dahan Apr 19 '17 at 21:23
  • Link no longer works... :( – Faizan Ahmed Feb 19 '21 at 05:42