I have an image element
<img id="image">
To manipulate the image I have the following buttons:-
<div class="btn-group">
<button type="button" class="js-zoom-in">
Zoom In
</button>
<button type="button" class="js-zoom-out">
Zoom Out
</button>
<button type="button" class="js-rotate-right">
Rotate Right
</button>
<button type="button" class="js-rotate-left">
Rotate Left
</button>
</div>
And to handle the corresponding events I am using the below jquery:-
<script>
var angle = 0;
var scale = 1;
$('.js-rotate-right').on('click', function() {
angle += 15;
$('#image').css('transform','rotate(' + angle + 'deg)');
});
$('.js-rotate-left').on('click', function() {
angle -= 15;
$('#image').css('transform','rotate(' + angle + 'deg)');
});
$('.js-zoom-in').on('click', function() {
scale += 0.25;
if(scale == 2.25){
scale = 2;
}
$('#image').css('transform','scale(' + scale + ')');
});
$('.js-zoom-out').on('click', function() {
scale -= 0.25;
if(scale == 0){
scale = 0.25;
}
$('#image').css('transform','scale(' + scale + ')');
});
</script>
If I rotate an image using these buttons and then try to zoom in or out the image gets restored to its original state. Same is the case when image is first scaled then rotated the image gets restored to original state.
I have even tried to do something like this:-
$('#image').css('transform','rotate(' + angle + 'deg)', 'scale(' + scale + ')');
for the following function:-
$('.js-rotate-right').on('click', function() {
angle += 15;
console.log(scale);
$('#image').css('transform','rotate(' + angle + 'deg)', 'scale(' + scale + ')');
});
But still no effect.