1 回答

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超10個(gè)贊
您可以添加一個(gè)白色 div 和過(guò)渡來(lái)包裹您的文本 div
class App extends Component {
state = {
random: false
};
toggleItem = () => {
this.setState({
random: !this.state.random
});
};
render() {
return (
<div>
<button onClick={this.toggleItem}>toggle item</button>
<br />
<div className="back">
Hello adsffd asdfadfs asdfasd asdfasdf asdfasfa fdasfas asdfasdf
afdsafas asdfasd asdfasdf asdfadsf asdfads asdfads asdfasdf
asdfadsadsf world Hello adsffd asdfadfs asdfasd asdfasdf asdfasfa
fdasfas asdfasdf afdsafas asdfasd asdfasdf asdfadsf asdfads asdfads
asdfasdf asdfadsadsf world Hello adsffd asdfadfs asdfasd asdfasdf
asdfasfa fdasfas asdfasdf afdsafas asdfasd asdfasdf asdfadsf asdfads
asdfads asdfasdf asdfadsadsf world Hello adsffd asdfadfs asdfasd
asdfasdf asdfasfa fdasfas asdfasdf afdsafas asdfasd asdfasdf
<CSSTransition
in={this.state.random}
timeout={1000}
classNames="alert"
unmountOnExit
>
<div className="white" />
</CSSTransition>
</div>
</div>
);
}
}
樣式.css
.alert-enter {
transform: translateY(400px);
}
.alert-enter-active {
transform: translateY(0px);
transition: all 1000ms;
}
.alert-exit {
transform: translateY(0px);
}
.alert-exit-active {
transform: translateY(800px);
transition: all 3000ms;
}
.back {
position: relative;
overflow: hidden;
}
.white {
height: 100%;
position: absolute;
top: 0;
left: 0;
background: white;
width: 100%;
}
您可以在這里檢查CodeSandBox。希望能幫助到你
- 1 回答
- 0 關(guān)注
- 205 瀏覽
添加回答
舉報(bào)