SHOW:
|
|
- or go back to the newest paste.
1 | <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
2 | <script> | |
3 | var work = $('body'); | |
4 | ||
5 | - | var backgrounds = new Array( |
5 | + | var backgroundUrls = [ |
6 | - | 'url(img/contentbackground1.jpg)' |
6 | + | 'img/contentbackground1.jpg', |
7 | - | , 'url(img/contentbackground2.jpg)' |
7 | + | 'img/contentbackground2.jpg', |
8 | - | , 'url(img/contentbackground3.jpg)' |
8 | + | 'img/contentbackground3.jpg', |
9 | - | , 'url(img/contentbackground4.jpg)' |
9 | + | 'img/contentbackground4.jpg' |
10 | - | ); |
10 | + | ]; |
11 | ||
12 | - | var current = 0; |
12 | + | var currentBackgroundIndex = 0; |
13 | - | |
13 | + | |
14 | - | function nextBackground(){ |
14 | + | function setNextBackground () { |
15 | - | current++; |
15 | + | work.css('background-image', 'url(' + backgrounds[currentBackgroundIndex] + ')'); |
16 | - | current = current % backgrounds.length; |
16 | + | currentBackgroundIndex++; |
17 | - | work.css('contentbackground1', backgrounds[current]); |
17 | + | } |
18 | - | } |
18 | + | |
19 | - | setInterval(nextBackground, 1000); |
19 | + | setNextBackground(); |
20 | setInterval(currentBackgroundIndex, 1000); | |
21 | - | work.css('contentbackground1', backgrounds[0]); |
21 | + | |
22 | </script> |