Binding onload event to jquery image object

Hi, I have a code on my website.

 backgroundImages[bg_img_path_b]=new Image();
 backgroundImages[bg_img_path_b].src =     bg_img_path_b;
 backgroundImages[bg_img_path_b].loaded="loading";
 //jQuery(backgroundImages[lastImage]).unbind('load.backgroundImages');                                         

 jQuery(backgroundImages[bg_img_path_b]).bind('load.backgroundImages',function(){
      if(typeof callback=='function'){
           callback.call(this, bg_img_path_b);
           if(showLoading) hideLoadingDC();
      }
 }).bind('load.cache', function(){
                            backgroundImages[bg_img_path_b].loaded="true";
                        });;

There is a large image of the fo gallery used as page wrapper background images. I need to preload the images due to speed (the images are quite large). So I have this code (in fact, this is only part of a larger function that includes caching, etc., but these few lines are triggered when the image is not in the cache).

backgroundImages is a large array of Image objects, the key is the path to the image. Each obejct image has my “uploaded” property, which says if the image is already uploaded or is currently in the upload state.

, ( ..)

I.E 9. ( ). , , , , , .

, , , IE, .

, , IE Chrome : (

, , , , ..

+3
2

, . , , onload, URL- Image URL-, .,

var photo = new Image();
photo.url = "http://www.something.com/something.jpg";
$(photo).bind('load',doSomething());


var photo = new Image();
$(photo).bind('load',doSomething());
photo.url = "http://www.something.com/something.jpg";

, ( IE). , propely..

+5

jQuery API ? jQuery.

JavaScript onload:

var myimages = new Array();
var path = "images/gallery/";

function preloadimages() {
    for (i = 0; i < preloadimages.arguments.length; i++) {
        myimages[i]=new Image();
        myimages[i].src=path+preloadimages.arguments[i];
    }
}

// Enter name of images to be preloaded inside parenthesis with douable quotes. 
// Extend list as desired with comma.
preloadimages("gImg1.jpg","gImg2.jpg","gImg3.jpg","gImg4.jpg" /*, etc...*/);
0

All Articles