Fading between two images based on time
Hey everyone, hopefully this will be a quick question for you guys.
Here's what I have going on. I have these two images at the very top of my body - they will serve as the background to the page.
- <img src="image1.jpg" id = "background" >
- <img src="image2.jpg" id = "background_hidden">
Here is the corresponding css for the two images:
-
- #background {
- width: 100%;
- height: 100%;
- z-index: -1;
- position: absolute;
- }
- #background_hidden {
- width: 100%;
- height: 100%;
- display: none;
- position: absolute;
- z-index: -1;
- }
Here's where javascript comes in. I'd like to have a simple method like this
- function changeBackground() {
-
- if (secs > 30) {
- //have image1
- }
- else {
- //have image2
- }
- }
The variable secs refers to the number of seconds in a minute. If the seconds is > 30, then have image1. As soon as the number of seconds cycles over 0 it should fade to image2.
I've been looking for ways to do this and am completely stuck.
Any insight would be great.