The example in this article describes the method of pre-loading jquery images. Share to everyone for your reference. Specifically as follows:
This code can preload the picture before the page is opened, which is useful and can give the user a better experience.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
function Preloadimages (Oimagelist, callback) {if (typeof (oimagelist) = = ' object ' && typeof (callback) = = "Func tion ") {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[iindex].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 your jquery programming.