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

How to implement preloading images with jQuery_jquery

WBOY
Release: 2016-05-16 16:09:01
Original
954 people have browsed it

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');
Copy after login

I hope this article will be helpful to everyone’s jQuery programming.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template