Sunday 15 February 2015

javascript - store folder contents (images) to var -


How can I store the content of a folder that has completely images I can do it like this < / P>

  var files = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg", "6.jpg", " 7.jpg "," 8.jpg "," 9.jpg "," 10.jpg ",];   

But I want to make it more dynamic I'm planning to create 100 images in the folder. I'm thinking something like this pseudo code number_of_items_in_folder images for var images [i] = image_from_folder

images coming from a folder (Local) images called

To do this on a client only you need a trick or a hardcoded value

then

  var images = []; // You tell the script how many are and the numbers of all 0 to to 87 (var i = 0; i & lt; 87; i ++) {images.push (i + ".jpg"); }   

If you do not know how many you have, then you must preload them

  var images = [], did = wrong, I = 0; While ((done!) {Var image = new image}; Image.error = function () {done = true;} Image.onload = function () {images.push (this.src);} Image.src = I + ".jpg"; i ++;}   

And if they have different names, then you need a server script that will create an array for you. / P>

No comments:

Post a Comment