I am facing an issue with a function that updates images by altering the src and css (width/height) of an IMG tag within the document. Below is a simplified example to demonstrate the problem:
updateImage = function(src, width, height) {
$("#changeMe").attr("src", src).css("width", width + "px").css("height", height + "px");
}
<img id="changeMe" />
<input type="button" onClick="updateImage('image1.jpg',100,150);" />
<input type="button" onClick="updateImage('image2.jpg',185,200);" />
<input type="button" onClick="updateImage('image3.jpg',50,100);" />
The issue arises when either the src or css properties change first, resulting in an awkward stretching effect due to varying image sizes. I am seeking advice on the best approach to resolve this.
I have already attempted hiding and re-showing the img before and after implementing the changes, but it did not solve the problem. Hopefully, someone with more expertise can provide a solution! :)