This article describes how to use jquery to pre-load images. This article describes how to use jQuery to operate images. For more information, see the following example. Share it with you for your reference. The details are as follows:
This code can be used to pre-load images before opening the page. This function is very useful and can provide a better user experience.
Function preloadImages (oImageList, callback) {if (typeof (oImageList) = 'object' & typeof (callback) = "function") {var iCallbackAfter = oImageList. length; var iPreloadInterval = window. setInterval (function () {if (iCallbackAfter = 0) {window. clearInterval (iPreloadInterval); callback () ;}, 100); $. each (oImageList, function (iIndex, sImage) {oImageList [iIndex] = new Image (); oImageList [I Index]. onload = function (oResult) {iCallbackAfter --;}; oImageList [iIndex]. onabort = function (oResult) {console. log (oResult) ;}; oImageList [iIndex]. onerror = function (oResult) {console. log (oResult) ;}; if (! SImage. match ('HTTP: // ') {sImage = sImage;} oImageList [iIndex]. src = sImage ;});}}
I hope this article will help you with jQuery programming.