I saw a comment on Ben Nadel's blog where Stephen Rushing posted a loader, but I can't figure out how I can pass the selectors and parameter...
I think I also need a completeCallback
and errorCallback
functions?
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
});
})
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…