【发布时间】:2019-07-24 03:37:47
【问题描述】:
我有一个绝对定位的 div:
class MyDiv extends React.Component {
state = {
stepCount: 0
};
componentDidMount(){
setInterval(() => {
this.setState({ stepCount: this.state.stepCount + 1 })
}, 1000);
}
render(){
return (<div style={{ left: this.state.stepCount * 10 + "%" }} />);
}
}
CSS
div { transition: 1s linear; }
每一秒,我将 div 左移 10%。 我希望过渡看起来平滑,但有轻微的口吃。
【问题讨论】:
-
react 有几个动画库,如果你打算在几个地方做不同类型的动画,使用一个库比做 manul css-transitions 更好。以
react-spring为例。