There are 0.png, 1.png, 2.png, ... in folder images. How to load all them. Number of the images unknown.
} while(!img[numOfImages].onerror);
alert("numOfImages = " + numOfImages);
var
numOfImages = 0;
img = [];
do{
img[numOfImages] = new Image();
img[numOfImages].src = "images/" + numOfImages + ".png";
numOfImages++;
} while(!img[numOfImages].onerror);
alert("numOfImages= " + numOfImages);
There are 0.png, 1.png, 2.png, ... in folder images. How to load all them. Number of the images unknown.
} while(!img[numOfImages].onerror);
alert("numOfImages = " + numOfImages);
var
numOfImages = 0;
img = [];
do{
img[numOfImages] = new Image();
img[numOfImages].src = "images/" + numOfImages + ".png";
numOfImages++;
} while(!img[numOfImages].onerror);
alert("numOfImages= " + numOfImages);
Share
Improve this question
asked Dec 12, 2015 at 11:07
Yaroslav ShabanovYaroslav Shabanov
2831 gold badge3 silver badges18 bronze badges
1 Answer
Reset to default 1Code:
var dir = "Src/themes/base/images/";
var fileextension = ".png";
$.ajax({
//This will retrieve the contents of the folder if the folder is configured as 'browsable'
url: dir,
success: function (data) {
//List all .png file names in the page
$(data).find("a:contains(" + fileextension + ")").each(function () {
var filename = this.href.replace(window.location.host, "").replace("http://", "");
$("body").append("<img src='" + dir + filename + "'>");
});
}
});
This will load all the image .png present in a folder, care that this code use jquery.