Home > Web Front-end > JS Tutorial > Common methods for preloading images with jQuery_jquery

Common methods for preloading images with jQuery_jquery

WBOY
Release: 2016-05-16 15:54:46
Original
1053 people have browsed it

The example in this article describes the common methods of preloading images in jQuery. Share it with everyone for your 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"
);
Copy after login

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"
);

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