var data = [
{
img:'http://mirpozitiva.ru/uploads/posts/2016-08/1472042512_05.jpg',
span:'Пространство для творчества',
active:0,
},
{
img:'http://wp.widewallpapers.ru/2k/nature/forest/1920x1200/forest-wallpaper-1920x1200-004.jpg',
span:'Пространство для творчества',
active:0,
},
{
img:'http://pulson.ru/wp-content/uploads/2013/03/pulson362.jpg',
span:'Пространство для творчества',
active:0,
},
];
html += '<div style="background: url('+dat.img+') no-repeat center center; background-size: cover;">';
$(this).append(html);
function ImagePreloader(imageUrls) {
var images = imageUrls.reduce(function (obj, url) {
var image = {
img: new Image()
};
image.loadingPromise = new Promise(function (resolve) {
image.img.onload = function () {
resolve(image);
};
});
image.img.src = url;
obj[url] = image;
return obj;
}, {});
this.onLoaded = function () {
return Promise.all(imageUrls.map(function (url) {
return images[url].loadingPromise;
}));
};
this.getImage = function (url) {
return images[url].loadingPromise;
};
};
var preloader = new ImagePreloader([
"http://farm4.static.flickr.com/3030/2618425424_e1d3b952ae.jpg?_=1234",
"http://farm4.static.flickr.com/3030/2618425424_e1d3b952ae.jpg?_=5678"
]);
preloader.onLoaded().then(function (images) {
console.log('all images loaded');
images.map(function(image) {
document.body.appendChild(image.img);
})
});