PP.Ui.ImagePreloader(settings);
settings. JSON object that contains values of class properties.
The ImagePreloader constructor creates an instance of the ImagePreloader class.
To execute the example, the HTML page must contain links to PP.js, PP.Util.js script files and to PP.css styles file. Create image loader and add several images:
function createImagePreloader() {
// Create image loader
imagePreloader = new PP.Ui.ImagePreloader({
// Set time out for image loading
Timeout: 5000,
// Set proxy server address
Proxy: "proxy",
// Set attribute of image loading without using the CORS technology
UseCORS: false,
// Disable the proxy server use for image loading
AllowTaint: false,
// Set image loading event handler
Preloaded: function (sender, args) {
console.log("All images are loaded");
}
});
// Add images for loading
imagePreloader._Images = {
address1: "../build/img/b_a_r.png",
address2: "../build/img/b_a_l.png"
}
}
Get all image being loaded:
// Get all image being loaded
console.log("Images being loaded:");
for (var i in imagePreloader.getImages()) {
console.log(imagePreloader.getImages()[i]);
}
As a result, the console displays all images being loaded:
Images being loaded:
../build/img/b_a_r.png
../build/img/b_a_l.png
Get image by the address1 address:
// Get the image by the address
console.log("Image by the address: " + imagePreloader.getImageBySrc("address1"));
As a result the console displays the image by the address:
../build/img/b_a_r.png
Load all images on the server:
// Load images imagePreloader.preload();
The console displays information about images loading:
All images are loaded
See also: