L
L
littleguga2015-04-04 02:14:17
css
littleguga, 2015-04-04 02:14:17

What is the best way to preload images in this case?

Good day! There are 30+ png files weighing 500kb each, they are shown on the page using css3 animation and js (toggle styles).
What's the best way to preload them?
<div id="preload1"></div>

#preload{
margin-left:  -9999px;
background: url(img1.png); 
display:block;
width: 1px;
height:1px;
}

and for each picture such a div? or in another way?
Thanks in advance for your reply!
UPD:
Regarding this decision , I read that it will not always load, because img must be on the page.
UPD 2:
On ipad'e:
ad25700f95a644d2836a631659522467.PNG26c24947b75045c89e7fe1580c04e97d.PNG

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2015-04-04
@littleguga

It needs to be loaded into memory, not into a 1x1 px DOM element.
I load backgrounds like this:

function preload() {
 bgpath='/images-bg';
 for (var i=0;i<=bgnummax-1;i++) {
  bgimages[i]=new Image();
  bgimages[i].src=bgpath+"/"+(i+1)+".jpg";
 }

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question