我正在尝试用 Reactjs 来实现这个效果。下面的 youtube 视频是我要实现的动画:
https://www.youtube.com/watch?v=WVBMiu1NPE&feature=youtu.be
现在我需要将它们变成一个 Reactjs 组件,我正在使用 react-addons-css-transition-group。我的代码应该做的是每次我按下按钮时,都会在 tabContent 数组中呈现一个 div 段落,然后应该由 ReactCSSTransitionGroup 对其进行动画处理。这是我的代码
constructor(props) {
super(props);
this.state = {
activeTab: 0
};
this.active = {
color: '#4286f4',
outline: 'none'
};
this.inactive = {};
}
customChange(tabNum) {
this.setState({
activeTab: tabNum
});
};
render() {
var tabContent = [<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>,
<div>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident
</div>,
<div>
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
veritatis et quasi architecto beatae vitae dicta sunt explicabo.
</div>,
<div>
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
</div>
]
return (
<div className='container-fluid mainDiv'>
<div id='TabsNav'>
<button style={this.state.activeTab === 0 ? this.active : this.inactive} onClick={() => {this.customChange(0)}} className='roundBorderLeft InfoButton'> <br/> btn1 </button>
<button style={this.state.activeTab === 1 ? this.active : this.inactive} onClick={() => {this.customChange(1)}} className='adjustLeft InfoButton'> <br/> btn2</button>
<button style={this.state.activeTab === 2 ? this.active : this.inactive} onClick={() => {this.customChange(2)}} className='adjustLeft InfoButton'> <br/> btn3</button>
<button style={this.state.activeTab === 3 ? this.active : this.inactive} onClick={() => {this.customChange(3)}} className='adjustLeft roundBorderRight InfoButton'> <br/> btn4</button>
</div>
<div id='TabContents'>
<ReactCSSTransitionGroup transitionName='tab' transitionEnterTimeout={2000} transitionLeaveTimeout={2000}>
{tabContent[this.state.activeTab]}
</ReactCSSTransitionGroup>
</div>
</div>
);
}
这是我用于过渡的 CSS 的一部分:
.tab-enter {
opacity: 0;
padding-left: 0;
-webkit-transition: opacity 2s, padding-left 2s;
}
.tab-enter.tab-enter-active {
opacity: 1;
padding-left: 100px;
}
.tab-leave {
opacity: 1;
padding-left: 100px;
-webkit-transition: opacity 2s, padding-left 2s;
}
.tab-leave.tab-leave-active {
opacity: 0;
padding-left: 200px;
}
.mainDiv {
padding-top: 100px;
padding-bottom: 100px;
color: grey;
background-color: #fafafa;
border-bottom: 1px solid #ebebeb;
}
我的代码没有显示动画,标签的内容立即出现,没有任何动画。我做错什么了?