Last active
January 2, 2016 13:29
-
-
Save wangwen1220/8310647 to your computer and use it in GitHub Desktop.
js: jQuery 图片预加载 | Preload images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // jQuery 图片预加载 | |
| (function($) { | |
| var cache = []; | |
| // Arguments are image paths relative to the current page. | |
| $.preLoadImages = function() { | |
| var args_len = arguments.length; | |
| for (var i = args_len; i--;) { | |
| var cacheImage = document.createElement('img'); | |
| cacheImage.src = arguments[i]; | |
| cache.push(cacheImage); | |
| } | |
| } | |
| })(jQuery); | |
| jQuery.preLoadImages("image1.gif", "/path/to/image2.png"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment