2015-10-21 17:53:38 +08:00
|
|
|
# 添加与删除
|
|
|
|
|
|
|
|
- order: 5
|
|
|
|
|
2015-10-23 22:37:42 +08:00
|
|
|
场景里有增加或删除条目时也会触发动画。
|
2015-10-21 17:53:38 +08:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
````jsx
|
2015-10-28 20:55:49 +08:00
|
|
|
import { QueueAnim, Button } from 'antd';
|
2015-10-23 22:37:42 +08:00
|
|
|
|
2015-10-28 20:55:49 +08:00
|
|
|
const Test = React.createClass({
|
2015-10-21 17:53:38 +08:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
show: true,
|
2015-10-23 22:37:42 +08:00
|
|
|
items: [
|
|
|
|
<li key="0"></li>,
|
|
|
|
<li key="1"></li>,
|
|
|
|
<li key="2"></li>
|
|
|
|
],
|
|
|
|
};
|
2015-10-21 17:53:38 +08:00
|
|
|
},
|
|
|
|
onClick() {
|
|
|
|
this.setState({
|
|
|
|
show: !this.state.show,
|
2015-10-23 22:37:42 +08:00
|
|
|
});
|
2015-10-21 17:53:38 +08:00
|
|
|
},
|
|
|
|
onAdd() {
|
2015-10-28 20:55:49 +08:00
|
|
|
let items = this.state.items;
|
2015-10-21 17:53:38 +08:00
|
|
|
items.push(<li key={Date.now()}></li>);
|
|
|
|
this.setState({
|
|
|
|
show: true,
|
|
|
|
items: items,
|
2015-10-23 22:37:42 +08:00
|
|
|
});
|
2015-10-21 17:53:38 +08:00
|
|
|
},
|
|
|
|
onRemove() {
|
2015-10-28 20:55:49 +08:00
|
|
|
let items = this.state.items;
|
2015-10-23 22:37:42 +08:00
|
|
|
items.splice(items.length - 1, 1);
|
2015-10-21 17:53:38 +08:00
|
|
|
this.setState({
|
|
|
|
show: true,
|
|
|
|
items: items,
|
2015-10-23 22:37:42 +08:00
|
|
|
});
|
2015-10-21 17:53:38 +08:00
|
|
|
},
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
2015-10-23 22:37:42 +08:00
|
|
|
<p className="buttons">
|
2015-10-21 17:53:38 +08:00
|
|
|
<Button type="primary" onClick={this.onClick}>切换</Button>
|
2015-10-23 22:37:42 +08:00
|
|
|
<Button onClick={this.onAdd} style={{marginLeft:10}}>添加</Button>
|
|
|
|
<Button onClick={this.onRemove} style={{marginLeft:10}}>删除</Button>
|
|
|
|
</p>
|
2015-10-21 17:53:38 +08:00
|
|
|
<div className="demo-content">
|
2015-10-23 22:37:42 +08:00
|
|
|
<div className="demo-listBox" key="b">
|
2015-10-21 17:53:38 +08:00
|
|
|
<div className="demo-list">
|
|
|
|
<div className="title"></div>
|
2015-10-23 22:37:42 +08:00
|
|
|
<QueueAnim component="ul" type={['right', 'left']}>
|
2015-11-25 17:35:49 +08:00
|
|
|
{this.state.show ? this.state.items : null}
|
2015-10-21 17:53:38 +08:00
|
|
|
</QueueAnim>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-23 22:37:42 +08:00
|
|
|
ReactDOM.render(<Test />, document.getElementById('components-queue-anim-demo-change'));
|
2015-10-21 17:53:38 +08:00
|
|
|
````
|