Home  >  Article  >  Web Front-end  >  How to implement preloading images with jQuery_jquery

How to implement preloading images with jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:09:01897browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn