【发布时间】:2020-06-25 23:58:11
【问题描述】:
我正在尝试使用按钮更新动画速度。按下按钮时,没有任何变化,但切换选项卡时,它会更新为设置的速度。
function Homepg() {
const [speed, setSpeed] = useState(15);
function faster () {
setSpeed(speed === 1 ? speed : speed-2)
};
function slower() {
setSpeed(speed+2);
}
const animationStyle = {
animation: `App-logo-spin infinite ${speed}s linear`
}
return (
<div className="App">
<header className="App-header">
<img src={logo} style={animationStyle} className="App-logo-circle" alt="White cross, with a blue bacground spining" id='spinnerLogo'/>
<p>Hello, and welcome to the begining of the Swiss Plus Website. <strong>We hope you enjoy your stay</strong></p>
<button className='App-button' id='fastLogoButton' onClick={faster}>Increase Spin Speed!</button>
<button className='App-button' id='slowLogoButton' onClick={slower}>Decrease Spin Speed!</button>
</header>
</div>
);
}
【问题讨论】:
标签: javascript html reactjs