I am trying to make a hot air balloon styled button that floats (translates over x and y space). Currently I am using CSS variable to set animation properties but I can only do this once or else I get an error saying
"TypeError: Cannot assign to read only property '--animation-time' of object '#'"
How do I work around this to be able to set new random properties for where the animation starts, ends, and how long it lasts?
Currently I have this:
class HotAir extends React.Component{
constructor(props){
super(props);
this.state = {
link: props.link,
cls: props.cls,
img: props.img,
text: props.text,
}
}
render(){
var cssProperties = {};
cssProperties['--animation-time'] = Math.random()*10 + 's';
console.log(cssProperties);
return(
<div className="balloon" style={cssProperties} onAnimationEnd={()=> cssProperties['--animation-time'] = '60s'}>
<Link to={this.state.link}><button className="balloonbutt">
<img src={this.state.img} alt=""></img>
<div className="balloontext">{this.state.text}</div></button>
</Link>
</div>
);
}
}
and this is my relevant css
.balloon{
--animation-time: 60s;
--x-float-start: 10vw;
--y-float-start: 10vh;
--x-float-end: 20vw;
--y-float-end: 20vh;
position: relative;
text-align: center;
color: white;
animation: float var(--animation-time) linear;
}
@keyframes float{
0%{
left: var(--x-float-start);
top: var(--y-float-start);
}
100%{
left: var(--x-float-end);
top: var(--y-float-end);
}
}