I am trying to display a gallery with multiple images, and i would like that each image would have a button to rotate each image.
So, following the idea of the answer of this question, I created below code:
const Root = document.documentElement,
gRoot = getComputedStyle(Root)
var RotateDeg = parseInt(gRoot.getPropertyValue('--turn'))
function rotate90() {
RotateDeg = (RotateDeg + 90) % 360
Root.style.setProperty('--turn', RotateDeg + "deg")
}
img {
width: auto;
height: auto;
image-rendering: pixelated;
}
:root {
--turn: 0deg;
}
#theImage {
-webkit-transform: rotate( var(--turn));
-moz-transform: rotate( var(--turn));
-ms-transform: rotate( var(--turn));
-o-transform: rotate( var(--turn));
transform: rotate( var(--turn));
}
<div class="card shadow-sm">
<img id="theImage" alt="text of my image 1" class="img-thumbnail card-img-top" property="contentUrl" src="myimage1.png" /><br/>
<div class="btn-group">
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="rotate90()">Rotar</button>
</div>
</div>
</div>
<div class="card shadow-sm">
<img id="theImage" alt="text of my image 2" class="img-thumbnail card-img-top" property="contentUrl" src="myimage2.png" /><br/>
<div class="btn-group">
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="rotate90()">Rotar</button>
</div>
</div>
</div>
So, it works partialy, the main problem I have is that when i click one button, it not only rotates its image but ALL images. I think the main reason is because it is using the same ID. The problem i have is that it is a gallery with thousand of images and i wouldn't like to create an ID for each image.
Is there any solution i could use here to rotate just 1 image without creating thousand of IDs?
Thank you!