-1
My question is this: I have in my code 2 JS functions that are called with onmouseenter and onmouseout in my HTML code, which are they:
function passo1() {
document.getElementById("imagem").src="imagens/002.png";
}
function passo2() {
document.getElementById("imagem").src="imagens/001.png";
}
The mouseenter event changes the image from 001.png to 002.png (in function Passo1), as the mouseout event changes the image from 002.png to 001.png (in function Passo2), that I descrivi is already working and the images exchange when passing and taking the mouse, the problem is that it gets something "dry", nor has any animation, I wondered if it would be possible to add some kind of animation or transition to these 2 images.
Guy most likely what you are trying to do would give to do easily with CSS... ever thought about it or have to be with JS even?
– hugocsl
But is it possible for CSS to replace src from an image? because it is not in the background of an element (if so, I know it would be possible to put a Hover and change the background), it is the <img element>
– Vinicius Verissimo Bazan
There are several options, you can have 2 images at the same time one above the other, which would be the MOST indicated, because when you change the src, you will have to load the other image, and this can make the image "blink" on the screen for a moment, 'cause it’s gonna be blank while you upload the new image. Having the two of you on top of each other would be fine. The other, more complex option is to have one element with two backgrounds-image, one url() for each image. I believe it is not possible to do "smooth transition" of src, even with JS
– hugocsl
I liked the idea of having one over the other, I could leave one with a bigger z-index and having the Hover the z-index would decrease, showing the other image, but for them to be on top of the other it would be necessary to mess with position, beyond the top and left.
– Vinicius Verissimo Bazan
Yes, you would have to use position, and you would actually just leave the image above with opacity:0; you don’t need z-index. But it all depends on the effect you want, if you want in the Hover an image goes out to the right and another one goes in to the left you won’t need position, you could use margin, so it all depends on what you really want... I just think landing is likely that you can make a CRS transition, plus the shipment problem I told you about...
– hugocsl
I get it, but thanks, really, I got a good idea of what to do.
– Vinicius Verissimo Bazan