Jako mocno początkujący w temacie js nie potrafię sobie poradzić z poniższym skryptem. A chodzi o to, że chciałbym, aby pobierał on obrazki ze wskazanego katalogu, a nie żebym musiał ręcznie podawać nazwy i ścieżki plików.
Znalazłem kilka rozwiązań i próbowałem wykorzystać funkcje glob czy readdir ale nie wiem czemu - nie działało mi to.
Czy mógłby ktoś na to zerknąć i doradzić jak stworzyć tablicę, z której skrypt będzie korzystał?
(Oryginalny skrypt pochodzi z http://srobbin.com/jquery-plugins/backstretch )
// Create an array of images that you'd like to use var images = new Array(); images[1] = "img/bg1.jpeg"; images[2] = "img/bg2.jpeg"; images[3] = "img/bg3.jpeg"; images[4] = "img/bg4.jpeg"; images[5] = "img/bg5.jpeg"; images[6] = "img/bg6.jpeg"; images[7] = "img/bg7.jpeg"; images[8] = "img/bg8.jpeg"; images[9] = "img/bg9.jpeg"; Array.prototype.shuffle = function() { var len = this.length; var i = len; while (i--) { var p = parseInt(Math.random()*len); var t = this[i]; this[i] = this[p]; this[p] = t; } }; images.shuffle(); // A little script for preloading all of the images // It"s not necessary, but generally a good idea $(images).each(function(){ $("<img/>")[0].src = this; }); // The index variable will keep track of which image is currently showing var index = 0; // Call backstretch for the first time, // In this case, I"m settings speed of 500ms for a fadeIn effect between images. $.backstretch(images[index], {speed: 500}); // Set an interval that increments the index and sets the new image // Note: The fadeIn speed set above will be inherited setInterval(function() { index = (index >= images.length - 1) ? 0 : index + 1; $.backstretch(images[index]); }, 5000);