-1

I have a one-page web site. It has 5 div, each with its content. I would like to know which div is displayed after user scrolls.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
bog
  • 1,323
  • 5
  • 22
  • 34
  • 1
    Please look at this answer [https://stackoverflow.com/questions/487073/how-to-check-if-element-is-visible-after-scrolling](https://stackoverflow.com/questions/487073/how-to-check-if-element-is-visible-after-scrolling) – Jakob Ladingkaer Feb 07 '20 at 19:41
  • An [Intersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) might work for this but you'll need to provide your code if you want us to help. – volt Feb 07 '20 at 19:56
  • You might also consider the jQuery inView plugin. Very easy to use. – gcdev Feb 07 '20 at 20:19

1 Answers1

0

I have used .is(":visible") with good results:

if ($("#id_of_item_to_check").is(":visible"))
    doSomething();

I'm not sure what you're trying to do, but if you wanted to, say, set a background-color to blue for the visible divs, and red for the others, you could:

$.each("div", function( key, value ) {
   if ($(this).is(":visible"))
      $(this).css("background-color","blue");
   else
      $(this).css("background-color","blue");
});