views:

75

answers:

1

What is the best way to determine if an element is truly visible on the page? As in pixels are being changed both because the element is not hidden via CSS and is in the visible part of a scrollable area (the window or some overflowing block element)?

I imagine I'll need to first check .is(':hidden') against the element and its parents. I would then need to iterate through all parents and the window, checking for overflow scroll/auto/hidden, then compare that parent element's scroll position and size against the original element's position and size. And I would also need to check for absolute positioning and look at z-indexes, as well.

Is there an easier way?

+2  A: 

There's a plugin for that. jQuery inview event plugin

mVChr
The plug-in doesn't really do what I need. It fires an event when an element is scrolled vertically into view, but doesn't allow me to simply check if an arbitrary element is visible.
MikeWyatt
Ah, didn't read well enough. I bet if you take a look at the single page worth of code for it though (http://remysharp.com/downloads/jquery.inview.js) you'll be able to adapt it to your situation.
mVChr