2016-08-14 47 views
0

我有一个反应组件,它接收两个其他组件,第一个组件始终呈现,第二个组件仅在选择组件时呈现。渲染后立即生成动画组件

ExpandableItem:

const propTypes = { 
    header: PropTypes.element.isRequired, 
    content: PropTypes.element.isRequired, 
    isSelected: PropTypes.bool.isRequired 
}; 

export default class ExpandableItem extends React.Component { 
    render() { 
     return (<li> 
      {this.props.header} 
      {this.props.isSelected && this.props.content} 
     </li>); 
    } 
} 

ExpandableItem.propTypes = propTypes; 

而当内容变得可见,该组件的高度变得更大了,我希望它是动画。

我该怎么做?

+1

你看着['ReactCSSTransitionGroup'(https://facebook.github.io/react/docs/animation.html)? –

回答

0

为什么不使用@keyframes和@ -moz-keframes与CSS类

+0

试过了,失败了,你能举个例子吗? – Pachu

+0

添加一个css-class到你的组件中,例如“my-component” 然后在你的css文件中添加这些: .my-component {0}动画:myAnim 0.3s ease; animation-fill-mode:forwards; 溢出:隐藏; } @keyframes myAnim { 0%{ height:0; } 100%高度:自动; } } – kiarashws