Browse Source

Improve Menu[inline] and Collapse animation, ref #4898

pull/4967/head
afc163 8 years ago
parent
commit
38c8360d1f
  1. 9
      components/_util/openAnimation.tsx
  2. 2
      components/collapse/index.tsx
  3. 2
      components/style/core/motion.less

9
components/_util/openAnimation.tsx

@ -1,4 +1,5 @@
import cssAnimation from 'css-animation'; import cssAnimation from 'css-animation';
import getRequestAnimationFrame from './getRequestAnimationFrame';
function animate(node, show, done) { function animate(node, show, done) {
let height; let height;
@ -6,16 +7,22 @@ function animate(node, show, done) {
start() { start() {
if (!show) { if (!show) {
node.style.height = `${node.offsetHeight}px`; node.style.height = `${node.offsetHeight}px`;
node.style.opacity = 1;
} else { } else {
height = node.offsetHeight; height = node.offsetHeight;
node.style.height = 0; node.style.height = 0;
node.style.opacity = 0;
} }
}, },
active() { active() {
node.style.height = `${show ? height : 0}px`; getRequestAnimationFrame()(() => {
node.style.height = `${show ? height : 0}px`;
node.style.opacity = show ? 1 : 0;
});
}, },
end() { end() {
node.style.height = ''; node.style.height = '';
node.style.opacity = '';
done(); done();
}, },
}); });

2
components/collapse/index.tsx

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import RcCollapse from 'rc-collapse'; import RcCollapse from 'rc-collapse';
import classNames from 'classnames'; import classNames from 'classnames';
import animation from '../_util/openAnimation';
export interface CollapseProps { export interface CollapseProps {
activeKey?: Array<string> | string; activeKey?: Array<string> | string;
@ -30,6 +31,7 @@ export default class Collapse extends React.Component<CollapseProps, any> {
static defaultProps = { static defaultProps = {
prefixCls: 'ant-collapse', prefixCls: 'ant-collapse',
bordered: true, bordered: true,
openAnimation: { ...animation, appear() {} },
}; };
render() { render() {

2
components/style/core/motion.less

@ -10,6 +10,6 @@
.ant-motion-collapse { .ant-motion-collapse {
overflow: hidden; overflow: hidden;
&-active { &-active {
transition: height .24s ease-in; transition: height .2s, opacity .2s;
} }
} }

Loading…
Cancel
Save