ant-design/components/_util/openAnimation.tsx

37 lines
724 B
TypeScript
Raw Normal View History

2016-03-30 16:27:14 +08:00
import cssAnimation from 'css-animation';
2015-08-25 11:11:21 +08:00
2016-03-30 16:27:14 +08:00
function animate(node, show, done) {
let height;
return cssAnimation(node, 'ant-motion-collapse', {
start() {
if (!show) {
node.style.height = `${node.offsetHeight}px`;
} else {
height = node.offsetHeight;
node.style.height = 0;
}
},
active() {
node.style.height = `${show ? height : 0}px`;
},
end() {
node.style.height = '';
2015-08-25 11:11:21 +08:00
done();
2016-03-30 16:27:14 +08:00
},
2015-08-25 11:11:21 +08:00
});
}
const animation = {
enter(node, done) {
2016-03-30 16:27:14 +08:00
return animate(node, true, done);
2015-08-25 11:11:21 +08:00
},
leave(node, done) {
2016-03-30 16:27:14 +08:00
return animate(node, false, done);
2015-08-25 11:11:21 +08:00
},
appear(node, done) {
2016-03-30 16:27:14 +08:00
return animate(node, true, done);
2015-08-25 11:11:21 +08:00
},
};
export default animation;