Home >Web Front-end >JS Tutorial >How to implement preloading images with jQuery_jquery
The example in this article describes how jQuery implements preloading images. Share it with everyone for your reference. The specific analysis is as follows:
This js code is used to preload the image. Remember it is preloading, not postloading. It means downloading the image to the cache of the user's browser before the image is displayed, so that it will be displayed when it is displayed. Very fast, no need to go to the server to read the image.
jQuery.preloadImages = function() { for(var i = 0; i < arguments.length; i++) { $("<img />").attr('src', arguments); } }; //用法 $.preloadImages('image1.gif','/path/to/image2.png','some/image3.jpg');
I hope this article will be helpful to everyone’s jQuery programming.