simplify a preload image function in jQuery
Posted
by robertdd
on Stack Overflow
See other posts from Stack Overflow
or by robertdd
Published on 2010-04-22T01:57:28Z
Indexed on
2010/04/22
2:03 UTC
Read the original article
Hit count: 287
after i spent 2 day searching a preload function in jQueryi with no succes, i manage to do this:
after i upload the image on server, in a list i get this:
<li id="upimagesDYGONI">
<div class="percentage">100%</div>
<div class="uploadifyProgress">
<div align=" center" class="uploadifyProgressBar" id="upimagesDYGONIProgressBar" style="width: 100%;">
<!--Progress Bar-->
</div>
</div>
</li>
with this function, i preload the image:
$.getlastimage = function(id) {
$.getJSON('operations.php', {'operation':'getli', 'id':id,}, function(lastimg){
$("#upimages" + id + " .percentage").text('processing');
$("#upimages" + id).append('<a href=""><img id="' + id + '" src="" alt="" /></a>')
.parent().attr({"href":"uploads/"+ lastimg +'?'+ (new Date()).getTime()});
$("#"+id).hide().attr({"src":"uploads/"+ lastimg +'?'+ (new Date()).getTime(), "alt":lastimg})
.load(function() {
$(this).show();
$("#upimages" + id + " .percentage").remove();
$("#upimages" + id + " .uploadifyProgress").remove();
});
});
}
})(jQuery)
and i get this:
<li id="upimagesLRBHYN" style="" class="">
<a href="uploads/0002.jpg?1271901177027">
<img alt="0002.jpg" src="uploads/0002.jpg?1271901177028" id="LRBHYN" style="display: block;">
</a>
</li>
how i can simplify the function? i want to use the full power of jQuery!! any idea?
© Stack Overflow or respective owner