I wrote this according to: Controlling image load order in HTML
I replaced the 'src' changing with '.attr' function, and it can't callback anymore. It stopped after changing once:
This line:I.src = imgAddresses[counter];
Into this:$("#page"+counter).attr("data-bgimage",imgAddresses[counter]);
Can you help me? Thank you very much!
HTML:
<div id="intro" class="slidingSpaces demo0" data-bgimage='' title="Intro">
<p>Hello</p>
<div id="page0" class="slidingSpaces demo0" data-bgimage='' title="Cover">
</div>
<div id="page1" class="slidingSpaces demo0" data-bgimage='' title="01">
</div>
<div id="page2" class="slidingSpaces demo0" data-bgimage='' title="02">
</div>
JS:
var imgAddresses = ['img1.png','img2.png','img3.png'];
function loadImage(counter) {
//Break out if no more images
if(counter==imgAddresses.length) { return; }
//Grab an image obj
var I = document.getElementById("page"+counter);
//Monitor load or error events, moving on to next image in either case
I.onload = I.onerror = function() { loadImage(counter+1); },
//Change source (then wait for event)
$("#page"+counter).attr("data-bgimage",imgAddresses[counter]);
}
loadImage(0);
Notice: "data-bgimage" is from FerroSlider jQuery Plugin. The div must use that for background-image.