jQuery chargement des images avec rappel complet

J'ai vu un commentaire sur Ben Nadel blog où Stephen se Précipiter posté un chargeur, mais je ne peux pas savoir comment je peux passer les sélecteurs et les paramètres..
Je pense que j'ai aussi besoin d'un completeCallback & errorCallback fonctions?

function imgLoad(img, completeCallback, errorCallback) {
    if (img != null && completeCallback != null) {
        var loadWatch = setInterval(watch, 500);
        function watch() {
            if (img.complete) {
                clearInterval(loadWatch);
                completeCallback(img);
            }
        }
    } else {
        if (typeof errorCallback == "function") errorCallback();
    }
}
//then call this from anywhere
imgLoad($("img.selector")[0], function(img) {
    $(img).fadeIn();
});

HTML:

<a href="#" class="tnClick" ><img id="myImage" src="images/001.jpg" /></a>

JS:

$(document).ready(function() {
    var newImage = "images/002.jpg";
    $("#myImage").css("display","none");
    $("a.tnClick").click(function() {
        //imgLoad here
    });
})

source d'informationauteur FFish | 2010-03-06