how to refresh a div after a period of time AND only if the div is in view

how to refresh a div after a period of time AND only if the div is in view

Hi.  I have a situation where I want to rotate content every x seconds but my app often sits in another tab out of view for a period of time.

Basically after a period of time, if the div is viewable by the user, I would like to refresh it.  How can I do this?

The time part is easily.  How do I also detect the div is in view?

Thanks.

J