Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var images = [];
- var str = "";
- for (var i = 0; i < 41; i++) {
- images[i] = 'image/bg/'+ (i + 1) +'.jpg';
- };
- function preloadImg(src) {
- $('<img/>')[0].src = src;
- }
- function shuffle(array) {
- var currentIndex = array.length, temporaryValue, randomIndex ;
- while (0 !== currentIndex) {
- randomIndex = Math.floor(Math.random() * currentIndex);
- currentIndex -= 1;
- temporaryValue = array[currentIndex];
- array[currentIndex] = array[randomIndex];
- array[randomIndex] = temporaryValue;
- }
- return array;
- }
- $.each(shuffle(images), function( index, value ) {
- preloadImg(value);
- str += "<div style='background-image: url("+ value +");' class='background"+ (index + 1) +"'></div>";
- });
- $("#background").append(str).children("div:gt(0)").hide();
- setInterval(function() {
- $('#background > div:first').fadeOut(1000)
- .next()
- .fadeIn(1000)
- .end()
- .appendTo('#background');
- }, 10000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement