Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. var images = [];
  2. var str = "";
  3. for (var i = 0; i < 41; i++) {
  4. images[i] = 'image/bg/'+ (i + 1) +'.jpg';
  5. };
  6.  
  7. function preloadImg(src) {
  8. $('<img/>')[0].src = src;
  9. }
  10. function shuffle(array) {
  11. var currentIndex = array.length, temporaryValue, randomIndex ;
  12. while (0 !== currentIndex) {
  13. randomIndex = Math.floor(Math.random() * currentIndex);
  14. currentIndex -= 1;
  15. temporaryValue = array[currentIndex];
  16. array[currentIndex] = array[randomIndex];
  17. array[randomIndex] = temporaryValue;
  18. }
  19. return array;
  20. }
  21. $.each(shuffle(images), function( index, value ) {
  22. preloadImg(value);
  23. str += "<div style='background-image: url("+ value +");' class='background"+ (index + 1) +"'></div>";
  24. });
  25. $("#background").append(str).children("div:gt(0)").hide();
  26. setInterval(function() {
  27. $('#background > div:first').fadeOut(1000)
  28. .next()
  29. .fadeIn(1000)
  30. .end()
  31. .appendTo('#background');
  32. }, 10000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement