I am wondering how to dynamically add and remove classes from an img tag. My goal is to change the image automatically every 2 seconds, similar to Instagram's signup page. I am struggling to achieve this using the material-ui approach. Below is a snippet of my code where I want to periodically add and remove certain classes.
<div className={classes.phoneImageWrapper}>
<img src={Phone1} alt="instagram" className={classes.phoneImage} />
<img src={Phone2} alt="instagram" className={classes.phoneImage} />
<img src={Phone3} alt="instagram" className={classes.phoneImage} />
<img src={Phone4} alt="instagram" className={classes.phoneImage} />
<img src={Phone5} alt="instagram" className={classes.phoneImage} />
</div>
Additionally, here are the styles I intend to toggle between adding and removing phoneImageAnimation and phoneImageVisible classes to the img tag every 2 seconds:
phoneImageWrapper: {
margin: "10px 0 0 151px",
position: "relative",
},
phoneImage: {
top: 100,
left: 0,
position: "absolute",
width: 240,
height: 427,
opacity: 0,
visibility: "hidden",
},
phoneImageAnimation: {
transition: "opacity 1.5s ease-in",
zIndex: 2,
},
phoneImageVisible: {
opacity: 1,
visibility: "visible",
}