Is there a way

to change the value of a variable whenever an image is scrolled off the screen?

For instance, picture two large images one on top of the other. When the user scrolls down far enough that the first image is off the screen I want a certain variable to change. Is that possible?

I looked into onblur but apparently that’s just when something is currently clicked on or selected.

Have you thought of setting up a timer function that wakes up every second or so and sees whether the image is still in the viewport. ?

No I haven’t! That sounds like it would be perfect! Do you know how to do that? It sounds difficult.

1 second is 1000 milliseconds, so the following should work:


var timer = setInterval(function () {
    // do stuff here
}, 1000);

By assigning it to a variable, you can then, should the need require it, cancel it at some later time.

Sorry, I’m a total noob at this! How do you set it to check and see if the image is off the screen?