Answer the question
In order to leave comments, you need to log in
JavaScript. How to display images one by one?
Good afternoon. I have some problem with the following script:
$(function(){
var t = $('div'), arr = ['1.jpg','2.jpg','3.jpg','4.jpg'...];
function loadImg(){
if( arr.length == 0 ) return;
var img = new Image(); img.src = arr[0];
img.onload = function(){
t.append(img);
arr.shift();
loadImg();
}
}
});
Answer the question
In order to leave comments, you need to log in
img.onload = function(){
t.append(img);
arr.shift();
setTimeout(loadImg,0);
}
More or less like this:
<script>
var i = 0;
var ras = "jpg";
function run(){
i++;
document.write('<img src="'+i+'.'+ras+'">');
}
setTimeout(run, 1000);//1секунда
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question