I am uploading an image via ajax and wanna instantly update them in the user profile picture element.
it works but the problem is, that the image is not moved perfectly until i refreshed the site 1-2 times.
var t = new Date().getTime(),
avatar = $("img.user-avatar"),
src = avatar.attr("src");
src = src.substr(0, src.indexOf("?") > 0 ? src.indexOf("?") : src.length);
avatar.attr("src", src + "?" + t);
resizeAndMoveAvatar();
the resizeAndMoveAvatar() function looks like this:
function resizeAndMoveAvatar()
{
var Avatar = $("img.user-avatar");
var w = Avatar.width(), h = Avatar.height();
Avatar.css({
'max-width': 'none',
'max-height': 'none'
});
if(w > h) {
Avatar.css('max-height', 32);
w = Avatar.width();
Avatar.css('left', -(w/2 - 32/2));
}
else if(h > w) {
Avatar.css('max-width', 32);
h = Avatar.height();
Avatar.css('top', -(h/2 - 32/2));
}
else {
Avatar.css({width: 32, height: 32});
}
}
when I update it its look like this:
but it should like this:
any suggestions how I can fix this problem?
thank you!