0

I am trying to run a function when in div comes in viewport, I tried to search it on google but did not found any effective jQuery view port detector plugin.

Please help me for detecting view port using jQuery

  • Useful: http://stackoverflow.com/questions/9255369/obtain-the-viewport-dimensions, http://stackoverflow.com/questions/10935888/highlight-element-that-is-closest-to-middle-of-viewport, http://stackoverflow.com/questions/8794338/how-to-get-the-height-and-width-of-the-browser-viewport-without-scrollbars-using – elclanrs Nov 04 '12 at 00:18
  • you suggested answers are for `height()` and `width()` , but my problem is differnt –  Nov 04 '12 at 00:22
  • I think as @elclanrs was suggesting via links, the way to go is to get the divs offset height from the top of the page, and then compare it to the distance the user has scrolled down the page using .scrollTop() http://api.jquery.com/scrollTop/ – Hank Nov 04 '12 at 00:45
  • as per suggestions above, you need to check the page on every scroll event, to check whether the *div* (or other element) is now visible. There is no DOM event that fires when an element is visible, so you're stuck with manually checking. – logical Chimp Nov 04 '12 at 00:55

1 Answers1

0

What you want to accomplish is a lot like lazy loading images (only you want to invoke your own custom function).

You can try to investigate lazyload jQuery plugin or Lazy-Load-Images-without-jQuery and carry on from there.

MasterAM
  • 16,283
  • 6
  • 45
  • 66