Common methods of jQuery preloading images
- 2020-06-15 07:38:02
- OfStack
This article illustrates the common methods of jQuery preloading images. Share to everybody for everybody reference. The details are as follows:
Method 1:
$.preloadImages = function() {
for (var i = 0; i<arguments.length; i++) {
img = new Image();
img.src = arguments[i];
}
}
$.preloadImages (
"path_to_image_array",
"path_to_image_array",
"path_to_image_array"
);
Method 2:
// JQUERY WAY TO PRELOAD IMAGES
// DOES NOT NEED TO BE IN DOCUMENT READY
$.preloadImages = function()
{
for(var i = 0; i<arguments.length; i++)
{
img = new Image();
img.src = arguments[i];
}
}
$.preloadImages(
"path/to/image/1",
"path/to/image/2",
"path/to/image/3"
);
Hopefully, this article has been helpful in your jQuery programming.