I'm using React and try to change 2 images by hovering them.
This is what I have done so far:
Card.js
<div className="image-wrapper">
<img src={sprites.front_default} className="image" alt="normal" />
<img src={sprites.back_default} className="image-hover" alt="hover" />
</div>
style.css
.image-wrapper {
position: relative;
}
.image-hover {
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: opacity 1s ease-out;
}
.image-hover:hover {
opacity: 1;
}
The main problem is that i want to make the front image opacity to 0 when im hovering the div, how can i make it?
I can make it without the fade changing but its important to make it with transition.
This is how I make it without transition
<img
className="figure"
src={sprites.front_default}
onMouseOver={(e) => (e.currentTarget.src = sprites.back_default)}
onMouseOut={(e) => (e.currentTarget.src = sprites.front_default)}
alt={"pokemon"}
/>
You can use just HTML & CSS. In the Card:
Here, I've used one class
pokemon-imageto position the two images at the center of theimage-wrapperelement, andpokemon-image--backas the class that is showed when hovering over theimage-wrapperelement.The CSS:
Hope this helps. You can try it in this codesandbox.