ReactCSSTransitionGroup对我没有任何作用,除了延迟我要显示的元素。我试图让我的组件在页面加载时淡入淡出。以下是有问题的代码:
import React from 'react';
import ReactCSSTransitionGroup from 'react/lib/ReactCSSTransitionGroup';
...
render() {
if(this.state.mounted) {
var child = (
<div>
<h1>{this.state.title}</h1>
<p>Description: {this.state.description}</p>
<p>Language(s): {this.state.lang}</p>
</div>
);
}
else {
var child = null;
}
return (
<div className="container">
<ReactCSSTransitionGroup transitionAppear={true} transitionAppearTimeout={1000} transitionName="puzzle" transitionEnterTimeout={500} transitionLeaveTimeout={300}>
{child}
</ReactCSSTransitionGroup>
</div>
)
}
这是用SASS编写的CSS:
.puzzle-appear {
opacity: .01;
.puzzle-appear-active {
opacity: 1;
transition: opacity 1000ms ease-in;
};
};
.puzzle-enter {
opacity: .01;
.puzzle-enter-active {
opacity: 1;
transition: opacity 500ms ease-in;
};
};
.puzzle-leave {
opacity: 1;
.puzzle-leave-active {
opacity: .01;
transition: opacity 300ms ease-in;
};
};
我已经尝试过谷歌提供的一些东西,但没有任何效果。然而,一切似乎都井然有序。代码有什么问题?
答案 0 :(得分:1)
你SASS代码建议将活动状态类应用于puzzle元素中的元素,但我不认为是这种情况。
如果您在渲染时可以看到正在应用的类,并且该位工作正常,那么这可能就是问题所在。将-active样式移出其当前嵌套位置。