2016-03-30 16:27:14 +08:00
|
|
|
import cssAnimation from 'css-animation';
|
2017-02-26 19:08:36 +08:00
|
|
|
import getRequestAnimationFrame, { cancelRequestAnimationFrame } from './getRequestAnimationFrame';
|
|
|
|
|
|
|
|
const reqAnimFrame = getRequestAnimationFrame();
|
2015-08-25 11:11:21 +08:00
|
|
|
|
2017-11-22 12:06:49 +08:00
|
|
|
function animate(node: HTMLElement, show: boolean, done: () => void) {
|
|
|
|
let height: number;
|
|
|
|
let requestAnimationFrameId: number;
|
2016-03-30 16:27:14 +08:00
|
|
|
return cssAnimation(node, 'ant-motion-collapse', {
|
|
|
|
start() {
|
|
|
|
if (!show) {
|
|
|
|
node.style.height = `${node.offsetHeight}px`;
|
2017-11-22 12:06:49 +08:00
|
|
|
node.style.opacity = '1';
|
2016-03-30 16:27:14 +08:00
|
|
|
} else {
|
|
|
|
height = node.offsetHeight;
|
2017-12-08 22:25:50 +08:00
|
|
|
node.style.height = '0px';
|
2017-11-22 12:06:49 +08:00
|
|
|
node.style.opacity = '0';
|
2016-03-30 16:27:14 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
active() {
|
2017-02-26 19:08:36 +08:00
|
|
|
if (requestAnimationFrameId) {
|
|
|
|
cancelRequestAnimationFrame(requestAnimationFrameId);
|
|
|
|
}
|
|
|
|
requestAnimationFrameId = reqAnimFrame(() => {
|
2017-02-20 15:34:16 +08:00
|
|
|
node.style.height = `${show ? height : 0}px`;
|
2017-11-22 12:06:49 +08:00
|
|
|
node.style.opacity = show ? '1' : '0';
|
2017-02-20 15:34:16 +08:00
|
|
|
});
|
2016-03-30 16:27:14 +08:00
|
|
|
},
|
|
|
|
end() {
|
2017-02-26 19:08:36 +08:00
|
|
|
if (requestAnimationFrameId) {
|
|
|
|
cancelRequestAnimationFrame(requestAnimationFrameId);
|
|
|
|
}
|
2016-03-30 16:27:14 +08:00
|
|
|
node.style.height = '';
|
2017-02-20 15:34:16 +08:00
|
|
|
node.style.opacity = '';
|
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 = {
|
2017-11-22 12:06:49 +08:00
|
|
|
enter(node: HTMLElement, done: () => void) {
|
2016-03-30 16:27:14 +08:00
|
|
|
return animate(node, true, done);
|
2015-08-25 11:11:21 +08:00
|
|
|
},
|
2017-11-22 12:06:49 +08:00
|
|
|
leave(node: HTMLElement, done: () => void) {
|
2016-03-30 16:27:14 +08:00
|
|
|
return animate(node, false, done);
|
2015-08-25 11:11:21 +08:00
|
|
|
},
|
2017-11-22 12:06:49 +08:00
|
|
|
appear(node: HTMLElement, done: () => void) {
|
2016-03-30 16:27:14 +08:00
|
|
|
return animate(node, true, done);
|
2015-08-25 11:11:21 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-03-14 12:52:06 +08:00
|
|
|
export default animation;
|