本文實例講述了jQuery預加載圖片常用方法。分享給大家供大家參考。具體如下:
方法1:
?
1 2 3 4 5 6 7 8 9 10 11 $.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" );方法2:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // 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" );希望本文所述對大家的jQuery程序設計有所幫助。