I have three images which need the transform style. The value for this style is generated and saved in array.
var img = [1.jpg, 2.jpg, 3.jpg]
var translateHoverValues = [60,120,180]
I get the the id of the image on hover, I have no idea how to pick the needed value from array based on id. Maybe there is some kind of index/position number of the img in the div, so I can pick the right value form array.
On hover I get the id of a image, like this:
onmouseover="imgHover(this)" //html
function imgHover(obj){ //JS
var idImg = obj.id //if logged gives back: img1, img2 or img3
var z = document.getElementById(idImg) //hovered image
z.style.transform = 'translateX(-'+translateHoverValues[n]+'px)'
......
}
My research:
https://www.w3schools.com/jsref/prop_element_children.asp
With children.length
I can tell that my div has length of 3, because 3 images.
With children[2]
we can select specific child, but how can we find out the index of hovered image?
Thank you.