1

I have a bunch of elements hidden due to having overflow:hidden on the parent element. I made a jQuery function that adds to the margin to make a new set of elements visible when a user clicks. However, I need a way to detect when the last element is visible so I can stop this feature from working once the end is reached.

The function I was using is this:

$(this).children('.Product').last().is(':visible')

I also tried:

$(this).children('.Product:last-child').is(':visible')

Both return false even when the last .Product element is visible on the screen.

Should this be working? Is there a better way that I could be doing this?

maembe
  • 1,270
  • 1
  • 13
  • 25

3 Answers3

0

Have you tried:

$(this).children('.Product:last').is(':visible');

If this doesn't work, try pasting the html code or creating a fiddle so we can help you better.

Vinny Fonseca
  • 450
  • 3
  • 10
0

:visible specifications says 'Elements are considered visible if they consume space in the document. Visible elements have a width or height that is greater than zero.' http://api.jquery.com/visible-selector/ I suppose it doesn't check if an element is into the view or not.

xpy
  • 5,481
  • 3
  • 29
  • 48
0

As mentioned, :visible will return true if they elements has visibility, ie they aren't display: none or they are still effecting the dom's flow of elements.

What you're after is if they are in the current users viewport:

See this Plugin: Viewport Selectors for jQuery

Good Luck!

Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291