JSFiddle - React, Tailwind, and code Playground
HTML
<div style="border: 1px solid red;">
<img id="myimage" src="http://upload.wikimedia.org/wikipedia/mediawiki/a/a9/Example.jpg" style="border: 3px solid silver;" />
</div>
<a href="#" id="myrotate">[ rotate ]</a>
JavaScript
function rotate(elm, deg) {
var offsetContLeft, offsetContTop, offsetLeft, offsetTop, newLeft, newTop;
$(elm).css('transform', 'rotate('+ deg +'deg)');
// Get the container offset
offsetContLeft = $(elm).parent().offset().left;
offsetContTop= $(elm).parent().offset().top;
// get the new rotated offset
offsetLeft = $(elm).offset().left;
offsetTop = $(elm).offset().top;
// Subtract the two offsets.
newLeft = offsetContLeft - offsetLeft;
newTop = offsetContTop - offsetTop;
// Apply the new offsets to the margin of the element.
$(elm).css('margin-left', newLeft).css('margin-top', newTop);
}
$("#myrotate").click(function (e) {
rotate('#myimage', 90);
});