A
A
Ayk722014-12-11 22:28:45
Browsers
Ayk72, 2014-12-11 22:28:45

Loading images into the browser cache, how to do?

Hello!
How to implement image loading in the HD gallery, the fact is that there are about 60 pictures and they need to be loaded so that the user does not wait for a long time to load each one, but while admiring one, others are already loaded in the meantime.
There is a code:

img= new Array();
img[0]=new Image();   // каринка 1
img[1]=new Image();   // каринка 2
img[2]=new Image();   // каринка 3

img[0].src="путь"
img[1].src=""
img[2].src=""

But I'm not entirely satisfied, tk. not beautiful.
I want something like:
var heroArray = [
'путь',
'путь',
'путь',
]

...

How to load them from var array?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Taratin, 2014-12-11
@Ayk72

heroArray.forEach(function(e){
new Image().src = e;
})

Y
Yago, 2014-12-11
@Yago

www.appelsiini.net/projects/lazyload

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question