I am writing an image rotation functionality. I have created an array to store degrees for transform function.
However I need to know instead of increment array, to move next and previous between the rotations array.
Switching from left and right doesn't work as expected.
https://jsfiddle.net/andreas20/v94zLg8b/
rotations = ['90deg', '180deg', '270deg', '360deg']
let img = document.getElementById('img_blob');
let array_increment = 0
$('#left').click(() => {
if (array_increment > 3)
array_increment = 0
img.style.transform = 'rotate(-' + rotations[array_increment] + ')'
array_increment++
console.log(array_increment)
})
$('#right').click(() => {
if (array_increment > 3)
array_increment = 0
img.style.transform = 'rotate(' + rotations[array_increment] + ')'
array_increment++
console.log(array_increment)
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="left">Left</button>
<button id="right">Right</button><br>
<img id="img_blob" src="https://i.imgur.com/vgD5ycf.jpg">