2019-01-12 11:33:27 +08:00
|
|
|
import cssAnimation from './css-animation';
|
|
|
|
import raf from 'raf';
|
2019-10-30 16:34:41 +08:00
|
|
|
import Vue from 'vue';
|
2017-12-07 18:33:33 +08:00
|
|
|
|
2019-02-01 17:23:00 +08:00
|
|
|
function animate(node, show, done) {
|
2019-01-12 11:33:27 +08:00
|
|
|
let height;
|
|
|
|
let requestAnimationFrameId;
|
|
|
|
let appearRequestAnimationFrameId;
|
2020-03-07 19:45:13 +08:00
|
|
|
return cssAnimation(node, 'ant-motion-collapse-legacy', {
|
2019-01-12 11:33:27 +08:00
|
|
|
start() {
|
2018-12-19 12:22:55 +08:00
|
|
|
if (appearRequestAnimationFrameId) {
|
2019-01-12 11:33:27 +08:00
|
|
|
raf.cancel(appearRequestAnimationFrameId);
|
2018-12-19 12:22:55 +08:00
|
|
|
}
|
2017-12-07 18:33:33 +08:00
|
|
|
if (!show) {
|
2019-01-12 11:33:27 +08:00
|
|
|
node.style.height = `${node.offsetHeight}px`;
|
|
|
|
node.style.opacity = '1';
|
2017-12-07 18:33:33 +08:00
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
height = node.offsetHeight;
|
2018-12-19 12:22:55 +08:00
|
|
|
// not get offsetHeight when appear
|
|
|
|
// set it into raf get correct offsetHeight
|
2018-12-25 22:17:45 +08:00
|
|
|
if (height === 0) {
|
2018-12-19 12:22:55 +08:00
|
|
|
appearRequestAnimationFrameId = raf(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
height = node.offsetHeight;
|
|
|
|
node.style.height = '0px';
|
|
|
|
node.style.opacity = '0';
|
|
|
|
});
|
2018-12-19 12:22:55 +08:00
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
node.style.height = '0px';
|
|
|
|
node.style.opacity = '0';
|
2018-12-19 12:22:55 +08:00
|
|
|
}
|
2017-12-07 18:33:33 +08:00
|
|
|
}
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
active() {
|
2017-12-07 18:33:33 +08:00
|
|
|
if (requestAnimationFrameId) {
|
2019-01-12 11:33:27 +08:00
|
|
|
raf.cancel(requestAnimationFrameId);
|
2017-12-07 18:33:33 +08:00
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
requestAnimationFrameId = raf(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
node.style.height = `${show ? height : 0}px`;
|
|
|
|
node.style.opacity = show ? '1' : '0';
|
|
|
|
});
|
2017-12-07 18:33:33 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
end() {
|
2018-12-19 12:22:55 +08:00
|
|
|
if (appearRequestAnimationFrameId) {
|
2019-01-12 11:33:27 +08:00
|
|
|
raf.cancel(appearRequestAnimationFrameId);
|
2018-12-19 12:22:55 +08:00
|
|
|
}
|
2017-12-07 18:33:33 +08:00
|
|
|
if (requestAnimationFrameId) {
|
2019-01-12 11:33:27 +08:00
|
|
|
raf.cancel(requestAnimationFrameId);
|
2017-12-07 18:33:33 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
node.style.height = '';
|
|
|
|
node.style.opacity = '';
|
|
|
|
done && done();
|
2017-12-07 18:33:33 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2017-12-07 18:33:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const animation = {
|
2019-01-12 11:33:27 +08:00
|
|
|
enter(node, done) {
|
2019-10-30 16:34:41 +08:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
animate(node, true, done);
|
|
|
|
});
|
2017-12-07 18:33:33 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
leave(node, done) {
|
|
|
|
return animate(node, false, done);
|
2017-12-07 18:33:33 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2017-12-07 18:33:33 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
export default animation;
|