Basically I’m trying to either fade in or out <div id="speech-bubble-sun"> or <div id="speech-bubble-dark">, dependent on the visibility of an animated fading div <div id="headlights">. So here is what I have so far.
I’m calling the if statement at different intervals throughout the function, and it does now work!
But, the if-statement ceases to work once the function has been called upon itself again (in the loop).
The “if” test is working fine.
“fadein” and “fadeout” are done asynchronously from your own code. i.e. Your own code continues to execute while the “headlights” div fades in/out.
When “fadeout” completes, the “headlights” div is set to “hidden” (not visible), but a fraction of a millisecond later it will become visible as it fades in then fades out.
So for over 99% of its time it will be visible, while for only less than 1% of the time (from the precise instant the “fadeout” completes till just before the “fadein” starts) it will be hidden, so you will almost always see the “speech-bubble-sun”, rather than “speech-bubble-dark”. You will not ping-pong between these two divs.