ant-design-vue/components/vc-tree/demo/animation.vue

73 lines
1.6 KiB
Vue
Raw Normal View History

2018-04-11 13:25:16 +00:00
<script>
/* eslint no-console:0 */
2019-01-12 03:33:27 +00:00
import Tree, { TreeNode } from '../index';
import '../assets/index.less';
import cssAnimation from '../../_util/css-animation';
2018-04-11 13:25:16 +00:00
function animate (node, show, done) {
2019-01-12 03:33:27 +00:00
let height = node.offsetHeight;
2018-04-11 13:25:16 +00:00
return cssAnimation(node, 'collapse', {
start () {
if (!show) {
2019-01-12 03:33:27 +00:00
node.style.height = `${node.offsetHeight}px`;
2018-04-11 13:25:16 +00:00
} else {
2019-01-12 03:33:27 +00:00
height = node.offsetHeight;
node.style.height = 0;
2018-04-11 13:25:16 +00:00
}
},
active () {
2019-01-12 03:33:27 +00:00
node.style.height = `${show ? height : 0}px`;
2018-04-11 13:25:16 +00:00
},
end () {
2019-01-12 03:33:27 +00:00
node.style.height = '';
done();
2018-04-11 13:25:16 +00:00
},
2019-01-12 03:33:27 +00:00
});
2018-04-11 13:25:16 +00:00
}
const animation = {
enter (node, done) {
2019-01-12 03:33:27 +00:00
return animate(node, true, done);
2018-04-11 13:25:16 +00:00
},
leave (node, done) {
2019-01-12 03:33:27 +00:00
return animate(node, false, done);
2018-04-11 13:25:16 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-04-11 13:25:16 +00:00
export default {
render () {
return (
<div>
<h2>expanded</h2>
<Tree
defaultExpandAll={false}
defaultExpandedKeys={['p1']}
openAnimation={{ on: animation, props: { appear: true }}}
>
<TreeNode title='parent 1' key='p1'>
<TreeNode key='p10' title='leaf'/>
<TreeNode title='parent 1-1' key='p11'>
<TreeNode title='parent 2-1' key='p21'>
<TreeNode title='leaf'/>
<TreeNode title='leaf'/>
</TreeNode>
<TreeNode key='p22' title='leaf'/>
</TreeNode>
</TreeNode>
</Tree>
</div>
2019-01-12 03:33:27 +00:00
);
2018-04-11 13:25:16 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-04-11 13:25:16 +00:00
</script>
<style>
.collapse {
overflow: hidden;
display: block;
}
.collapse-active {
transition: height 0.3s ease-out;
}
</style>