Correct me if I'm wrong:
- An image upload form, using AJAX Upload, allows users to upload an image onto your server.
- AJAX Upload calls an
onComplete callback with the URI of the newly-uploaded image.
- You create a new
img DOM element with src set to the URI of the uploaded image.
- The
img DOM element is added to the document.
showhide is called on the img element.
If this is correct, then it explains why elementWidth and elementHeight are sometimes not correct. The problem is that the browser needs time to download the image, and elementWidth and elementHeight are not valid until the image has been fully loaded.
To fix this problem, I would try calling showhide in a load callback on the img that is registered before the src attribute is set:
var $myNewImage = $('<li><img alt="" /></li>'),
$i = $myNewImage.children('img');
$i.hide();
$myNewImage.rightClick(function(e) {
// ....
});
$myNewImage.prependTo('.uploadedImages');
$('.uploadedImages li').each(function() {
var indexNumber = $(this).index();
$(this).children('img').attr('id', 'image_' + indexNumber);
});
$i.load(function() {
$i.showhide({ appear: true });
});
$i.attr('src', 'uploads/thumbs/' + file);