gpt4 book ai didi

css - ReactCSSTransitionGroup 有什么问题?

转载 作者:太空宇宙 更新时间:2023-11-04 02:15:33 24 4
gpt4 key购买 nike

我在组件的 render() 函数中有这段代码:

..
<ReactCSSTransitionGroup
transitionName="testing"
transitionEnterTimeout={600}
transitionLeaveTimeout={600}>

<div>testing animations!</div>

</ReactCSSTransitionGroup>
..

我的 CSS 文件中有这段代码:

.testing-enter {
animation: slideIn 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.testing-leave {
animation: slideOut 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
}

@keyframes slideIn {
0% {
opacity 0
transform translate3d(-50px, 0, 0)
}
100% {
opacity 1
transform translate3d(0, 0, 0)
}
}
@keyframes slideOut {
0% {
opacity: 1
transform: translate3d(0, 0, 0)
}
100% {
opacity: 0
transform: translate3d(50px, 0, 0)
}
}

我只是想让我的 div block 从右边滑入,但是没有任何反应!找不到错误的代码,看起来一切正常。

最佳答案

<ReactCSSTransitionGroup/> 中有静态内容标签。你需要有动态内容。假设您需要渲染 <div>testing animations!</div>单击鼠标后。您需要将子项分配给一个变量并在单击鼠标时修改该变量。

let myDiv = buttonClicked ? <div>testing animations!</div> : <div></div>

<ReactCSSTransitionGroup
transitionName="testing"
transitionEnterTimeout={600}
transitionLeaveTimeout={600}>

{myDiv}

</ReactCSSTransitionGroup>

如果没有执行任何操作,而您只需要在初始安装时为其设置动画,请改用 transition-appear。

ReactCSSTransitionGroup provides the optional prop transitionAppear, to add an extra transition phase at the initial mount of the component. There is generally no transition phase at the initial mount as the default value of transitionAppear is false. The following is an example which passes the prop transitionAppear with the value true.

<ReactCSSTransitionGroup transitionName="example" transitionAppear={true} transitionAppearTimeout={500}>
<div>testing animations!</div>
</ReactCSSTransitionGroup>


.example-appear {
opacity: 0.01;
}

.example-appear.example-appear-active {
opacity: 1;
transition: opacity .5s ease-in;
}

关于css - ReactCSSTransitionGroup 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38965622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com