You can create a javascript method which checks all images whether they are loaded or not.
var preLoadImages = function (arr) {
var newImages = [], // temparary variable containing loaded images
loadedImagesCount = 0; //
var postAction = function () {};
var arr = (typeof arr != "object") ? [arr] : arr; // if a single image is sent, convert it into array
function imageLoadPost() {
loadedImagesCount++;
if (loadedImagesCount == arr.length) {
postAction(newImages) // postAction method
}
}
for (var i = 0; i < arr.length; i++) {
newImages[i] = new Image();
newImages[i].src = arr[i];
newImages[i].onload = function () { // call imageLoadPost when image is loaded
imageLoadPost();
}
newImages[i].onerror = function () { // call imageLoadPost when error occurred because its also an success event which already checked whether mage is available or not
imageLoadPost();
}
}
return { //return blank object with done() method
done: function (f) {
postAction = f || postAction // user defined callback method to be called when all images are loaded
}
}
}
// image array contains all images which you want to preload - currently having sample images
var imgArr = ['http://doc.jsfiddle.net/_images/jsfiddle-logo-thumb.png', 'http://doc.jsfiddle.net/_images/jsfiddle-desktop-thumbnail-a.png'];
preLoadImages(imgArr).done(function (imgArr) {
alert('all images loaded');
// call your carousel here
})
In done method, you can create your carousel. You need to add this method in a file and put that in top of the stack where you load your javascript files.
JSFiddle link