组件演示

[{"title":"基本使用","id":"components-animate-demo-basic","tags":[],"filepath":"site/components/animate/demo/basic.md","directory":"components/animate/demo","filename":"basic","meta":{"title":"基本使用","description":"\n<p>默认提供的动画样式,只有入场动画。</p>\n","order":"0","filepath":"site/components/animate/demo/basic.md","filename":"basic","directory":"components/animate/demo","id":"components-animate-demo-basic","template":"demos","html":"<script>(function(){'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _uxcore = require('uxcore');\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar Option = _uxcore.Select.Option;\n\nvar AwesomeComponent = function (_React$Component) {\n _inherits(AwesomeComponent, _React$Component);\n\n function AwesomeComponent(props) {\n _classCallCheck(this, AwesomeComponent);\n\n return _possibleConstructorReturn(this, (AwesomeComponent.__proto__ || Object.getPrototypeOf(AwesomeComponent)).call(this, props));\n }\n\n _createClass(AwesomeComponent, [{\n key: 'render',\n value: function render() {\n return React.createElement(\n 'div',\n { style: { display: this.props.visible ? 'inline-block' : 'none' }, className: 'awesome-component-wrap bg-primary-color' },\n '\\u52A8\\u753B\\u5C55\\u793A\\u533A\\u57DF'\n );\n }\n }]);\n\n return AwesomeComponent;\n}(React.Component);\n\nvar Demo = function (_React$Component2) {\n _inherits(Demo, _React$Component2);\n\n function Demo(props) {\n _classCallCheck(this, Demo);\n\n var _this2 = _possibleConstructorReturn(this, (Demo.__proto__ || Object.getPrototypeOf(Demo)).call(this, props));\n\n _this2.state = {\n visible: true,\n effect: 'fade'\n };\n return _this2;\n }\n\n _createClass(Demo, [{\n key: 'showComponent',\n value: function showComponent() {\n this.setState({\n visible: !this.state.visible\n });\n }\n }, {\n key: 'handleChange',\n value: function handleChange(value) {\n this.setState({\n effect: value\n });\n }\n }, {\n key: 'render',\n value: function render() {\n var effects = ['fade', 'slideRight', 'slideDown', 'newspaper', 'fall', 'threeFallH', 'threeFallV', 'threeSign', 'superScale', 'threeSlit', 'threeRotateBottom', 'threeRotateLeft'];\n return React.createElement(\n 'div',\n null,\n React.createElement(\n 'div',\n { style: { height: '60px' } },\n React.createElement(\n _uxcore.Animate,\n { showProp: 'visible', transitionName: this.state.effect, transitionAppear: true },\n React.createElement(AwesomeComponent, { visible: this.state.visible })\n )\n ),\n React.createElement(\n 'div',\n { style: { padding: '10px 0px' } },\n React.createElement(\n _uxcore.Select,\n { style: { width: '200px' }, placeholder: '\\u5207\\u6362\\u52A8\\u753B\\u6548\\u679C', onChange: this.handleChange.bind(this), value: this.state.effect },\n effects.map(function (item) {\n return React.createElement(\n Option,\n { key: item },\n item\n );\n })\n ),\n React.createElement(\n _uxcore.Button,\n { type: 'outline', onClick: this.showComponent.bind(this), style: { marginLeft: '10px' } },\n '\\u663E\\u793A/\\u9690\\u85CF'\n )\n )\n );\n }\n }]);\n\n return Demo;\n}(React.Component);\n\nReactDOM.render(React.createElement(Demo, null), document.getElementById('components-animate-demo-basic'));})()</script><div class=\"highlight\"><pre><code class=\"javascript\">\nimport { Button } from 'uxcore';\nimport { Animate } from 'uxcore';\nimport { Select } from 'uxcore';\nconst { Option } = Select;\n\nclass AwesomeComponent extends React.Component {\n constructor(props) {\n super(props);\n }\n render() {\n return (\n &lt;div style={{ display: this.props.visible ? 'inline-block' : 'none' }} className=\"awesome-component-wrap bg-primary-color\"&gt;\n 动画展示区域\n &lt;/div&gt;\n );\n }\n}\n\nclass Demo extends React.Component {\n\n constructor(props) {\n super(props);\n this.state = {\n visible: true,\n effect: 'fade',\n };\n }\n\n showComponent() {\n this.setState({\n visible: !this.state.visible,\n });\n }\n\n handleChange(value) {\n this.setState({\n effect: value,\n });\n }\n\n render() {\n const effects = ['fade', 'slideRight', 'slideDown', 'newspaper', 'fall', 'threeFallH', 'threeFallV', 'threeSign', 'superScale', 'threeSlit', 'threeRotateBottom', 'threeRotateLeft'];\n return (\n &lt;div&gt;\n &lt;div style={{ height: '60px' }}&gt;\n &lt;Animate showProp=\"visible\" transitionName={this.state.effect} transitionAppear&gt;\n &lt;AwesomeComponent visible={this.state.visible} /&gt;\n &lt;/Animate&gt;\n &lt;/div&gt;\n &lt;div style={{ padding: '10px 0px' }}&gt;\n &lt;Select style={{ width: '200px' }} placeholder=\"切换动画效果\" onChange={this.handleChange.bind(this)} value={this.state.effect}&gt;\n {effects.map(item =&gt; &lt;Option key={item}&gt;{item}&lt;/Option&gt;)}\n &lt;/Select&gt;\n &lt;Button type=\"outline\" onClick={this.showComponent.bind(this)} style={{ marginLeft: '10px' }}&gt;显示/隐藏&lt;/Button&gt;\n &lt;/div&gt;\n &lt;/div&gt;\n );\n }\n}\n\nReactDOM.render(\n &lt;Demo /&gt;\n, document.getElementById('components-animate-demo-basic'));</code></pre></div><style type=\"text/css\">.awesome-component-wrap {\n color: white;\n line-height: 40px;\n padding: 10px 20px;\n border-radius: 10px;\n font-size: 16px;\n}</style><div class=\"highlight\"><pre><code class=\"css\"><span class=\"hljs-class\">.awesome-component-wrap</span> <span class=\"hljs-rules\">{\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">color</span>:<span class=\"hljs-value\"> white</span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">line-height</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">40px</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">padding</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">10px</span> <span class=\"hljs-number\">20px</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">border-radius</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">10px</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">font-size</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">16px</span></span></span>;\n}</span></code></pre></div>"},"status":"public","toc":""},{"title":"定制动画","id":"components-animate-demo-custom","tags":[],"filepath":"site/components/animate/demo/custom.md","directory":"components/animate/demo","filename":"custom","meta":{"title":"定制动画","description":"\n<p>默认提供的动画样式,只有入场动画。</p>\n","order":"1","filepath":"site/components/animate/demo/custom.md","filename":"custom","directory":"components/animate/demo","id":"components-animate-demo-custom","template":"demos","html":"<script>(function(){'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _uxcore = require('uxcore');\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar Option = _uxcore.Select.Option;\n\nvar AwesomeComponent = function (_React$Component) {\n _inherits(AwesomeComponent, _React$Component);\n\n function AwesomeComponent(props) {\n _classCallCheck(this, AwesomeComponent);\n\n return _possibleConstructorReturn(this, (AwesomeComponent.__proto__ || Object.getPrototypeOf(AwesomeComponent)).call(this, props));\n }\n\n _createClass(AwesomeComponent, [{\n key: 'render',\n value: function render() {\n return React.createElement(\n 'div',\n { style: { display: this.props.visible ? 'inline-block' : 'none' }, className: 'awesome-component-wrap bg-primary-color' },\n '\\u52A8\\u753B\\u5C55\\u793A\\u533A\\u57DF'\n );\n }\n }]);\n\n return AwesomeComponent;\n}(React.Component);\n\nvar Demo = function (_React$Component2) {\n _inherits(Demo, _React$Component2);\n\n function Demo(props) {\n _classCallCheck(this, Demo);\n\n var _this2 = _possibleConstructorReturn(this, (Demo.__proto__ || Object.getPrototypeOf(Demo)).call(this, props));\n\n _this2.state = {\n visible: true\n };\n return _this2;\n }\n\n _createClass(Demo, [{\n key: 'showComponent',\n value: function showComponent() {\n this.setState({\n visible: !this.state.visible\n });\n }\n }, {\n key: 'render',\n value: function render() {\n return React.createElement(\n 'div',\n null,\n React.createElement(\n 'div',\n { style: { height: '60px' } },\n React.createElement(\n _uxcore.Animate,\n { showProp: 'visible', transitionName: 'custom', transitionAppear: true, onEnd: function onEnd(key, exists) {\n console.log(key, exists);\n }\n },\n React.createElement(AwesomeComponent, { key: 'awesome', visible: this.state.visible })\n )\n ),\n React.createElement(\n 'div',\n { style: { padding: '10px 0px' } },\n React.createElement(\n _uxcore.Button,\n { type: 'outline', onClick: this.showComponent.bind(this), style: { marginLeft: '10px' } },\n '\\u663E\\u793A/\\u9690\\u85CF'\n )\n )\n );\n }\n }]);\n\n return Demo;\n}(React.Component);\n\nReactDOM.render(React.createElement(Demo, null), document.getElementById('components-animate-demo-custom'));})()</script><div class=\"highlight\"><pre><code class=\"javascript\">\n<span class=\"hljs-keyword\">import</span> { Button } <span class=\"hljs-keyword\">from</span> <span class=\"hljs-string\">'uxcore'</span>;\n<span class=\"hljs-keyword\">import</span> { Animate } <span class=\"hljs-keyword\">from</span> <span class=\"hljs-string\">'uxcore'</span>;\n<span class=\"hljs-keyword\">import</span> { Select } <span class=\"hljs-keyword\">from</span> <span class=\"hljs-string\">'uxcore'</span>;\n<span class=\"hljs-keyword\">const</span> { Option } = Select;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">AwesomeComponent</span> <span class=\"hljs-keyword\">extends</span> <span class=\"hljs-title\">React</span>.<span class=\"hljs-title\">Component</span> </span>{\n constructor(props) {\n <span class=\"hljs-keyword\">super</span>(props);\n }\n render() {\n <span class=\"hljs-keyword\">return</span> (\n <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">div</span> <span class=\"hljs-attribute\">style</span>=<span class=\"hljs-value\">{{</span> <span class=\"hljs-attribute\">display:</span> <span class=\"hljs-attribute\">this.props.visible</span> ? '<span class=\"hljs-attribute\">inline-block</span>' <span class=\"hljs-attribute\">:</span> '<span class=\"hljs-attribute\">none</span>' }} <span class=\"hljs-attribute\">className</span>=<span class=\"hljs-value\">\"awesome-component-wrap bg-primary-color\"</span>&gt;</span>\n 动画展示区域\n <span class=\"hljs-tag\">&lt;/<span class=\"hljs-title\">div</span>&gt;</span>\n )</span>;\n }\n}\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">Demo</span> <span class=\"hljs-keyword\">extends</span> <span class=\"hljs-title\">React</span>.<span class=\"hljs-title\">Component</span> </span>{\n\n constructor(props) {\n <span class=\"hljs-keyword\">super</span>(props);\n <span class=\"hljs-keyword\">this</span>.state = {\n visible: <span class=\"hljs-literal\">true</span>,\n };\n }\n\n showComponent() {\n <span class=\"hljs-keyword\">this</span>.setState({\n visible: !<span class=\"hljs-keyword\">this</span>.state.visible,\n });\n }\n\n render() {\n <span class=\"hljs-keyword\">return</span> (\n <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">div</span>&gt;</span>\n <span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">div</span> <span class=\"hljs-attribute\">style</span>=<span class=\"hljs-value\">{{</span> <span class=\"hljs-attribute\">height:</span> '<span class=\"hljs-attribute\">60px</span>' }}&gt;</span>\n <span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">Animate</span> <span class=\"hljs-attribute\">showProp</span>=<span class=\"hljs-value\">\"visible\"</span> <span class=\"hljs-attribute\">transitionName</span>=<span class=\"hljs-value\">{'custom'}</span> <span class=\"hljs-attribute\">transitionAppear</span> <span class=\"hljs-attribute\">onEnd</span>=<span class=\"hljs-value\">{(key,</span> <span class=\"hljs-attribute\">exists</span>) =&gt;</span> {\n console.log(key, exists);\n }}\n &gt;\n <span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">AwesomeComponent</span> <span class=\"hljs-attribute\">key</span>=<span class=\"hljs-value\">\"awesome\"</span> <span class=\"hljs-attribute\">visible</span>=<span class=\"hljs-value\">{this.state.visible}</span> /&gt;</span>\n <span class=\"hljs-tag\">&lt;/<span class=\"hljs-title\">Animate</span>&gt;</span>\n <span class=\"hljs-tag\">&lt;/<span class=\"hljs-title\">div</span>&gt;</span>\n <span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">div</span> <span class=\"hljs-attribute\">style</span>=<span class=\"hljs-value\">{{</span> <span class=\"hljs-attribute\">padding:</span> '<span class=\"hljs-attribute\">10px</span> <span class=\"hljs-attribute\">0px</span>' }}&gt;</span>\n <span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">Button</span> <span class=\"hljs-attribute\">type</span>=<span class=\"hljs-value\">\"outline\"</span> <span class=\"hljs-attribute\">onClick</span>=<span class=\"hljs-value\">{this.showComponent.bind(this)}</span> <span class=\"hljs-attribute\">style</span>=<span class=\"hljs-value\">{{</span> <span class=\"hljs-attribute\">marginLeft:</span> '<span class=\"hljs-attribute\">10px</span>' }}&gt;</span>显示/隐藏<span class=\"hljs-tag\">&lt;/<span class=\"hljs-title\">Button</span>&gt;</span>\n <span class=\"hljs-tag\">&lt;/<span class=\"hljs-title\">div</span>&gt;</span>\n <span class=\"hljs-tag\">&lt;/<span class=\"hljs-title\">div</span>&gt;</span>\n )</span>;\n }\n}\n\nReactDOM.render(\n <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">Demo</span> /&gt;</span>\n, document.getElementById('components-animate-demo-custom'));</span></code></pre></div><style type=\"text/css\">.awesome-component-wrap {\n color: white;\n line-height: 40px;\n padding: 10px 20px;\n border-radius: 10px;\n font-size: 16px;\n}\n\n@keyframes flipIn {\n 0% {\n opacity: 0;\n transform: perspective(1000px) rotate3d(1,0,0,45deg);\n }\n 100% {\n opacity: 1;\n transform: perspective(1000px) rotate3d(1,0,0,0deg);\n }\n}\n\n@keyframes flipOut {\n 0% {\n opacity: 1;\n transform: perspective(1000px) rotate3d(1,0,0,0deg);\n }\n 100% {\n opacity: 0;\n transform: perspective(1000px) rotate3d(1,0,0,45deg);\n }\n}\n\n.custom-enter,\n.custom-appear {\n opacity: 0;\n transform: perspective(1000px) rotate3d(1,0,0,45deg);\n transform-origin: 50% calc(100% + 10px);\n animation-duration: 1s;\n animation-fill-mode: both;\n}\n.custom-enter-active,\n.custom-appear-active {\n animation-name: flipIn;\n}\n\n.custom-leave {\n opacity: 1;\n transform: perspective(1000px) rotate3d(1,0,0,0deg);\n animation-duration: 1s;\n animation-fill-mode: both;\n}\n\n.custom-leave-active {\n animation-name: flipOut;\n}</style><div class=\"highlight\"><pre><code class=\"css\"><span class=\"hljs-class\">.awesome-component-wrap</span> <span class=\"hljs-rules\">{\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">color</span>:<span class=\"hljs-value\"> white</span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">line-height</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">40px</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">padding</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">10px</span> <span class=\"hljs-number\">20px</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">border-radius</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">10px</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">font-size</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">16px</span></span></span>;\n}</span>\n\n<span class=\"hljs-at_rule\">@<span class=\"hljs-keyword\">keyframes</span> flipIn </span>{\n 0% <span class=\"hljs-rules\">{\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">opacity</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">0</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">transform</span>:<span class=\"hljs-value\"> <span class=\"hljs-function\">perspective</span>(<span class=\"hljs-number\">1000px</span>) <span class=\"hljs-function\">rotate3d</span>(<span class=\"hljs-number\">1</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">45deg</span>)</span></span>;\n }</span>\n 100% <span class=\"hljs-rules\">{\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">opacity</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">1</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">transform</span>:<span class=\"hljs-value\"> <span class=\"hljs-function\">perspective</span>(<span class=\"hljs-number\">1000px</span>) <span class=\"hljs-function\">rotate3d</span>(<span class=\"hljs-number\">1</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">0deg</span>)</span></span>;\n }</span>\n}\n\n<span class=\"hljs-at_rule\">@<span class=\"hljs-keyword\">keyframes</span> flipOut </span>{\n 0% <span class=\"hljs-rules\">{\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">opacity</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">1</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">transform</span>:<span class=\"hljs-value\"> <span class=\"hljs-function\">perspective</span>(<span class=\"hljs-number\">1000px</span>) <span class=\"hljs-function\">rotate3d</span>(<span class=\"hljs-number\">1</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">0deg</span>)</span></span>;\n }</span>\n 100% <span class=\"hljs-rules\">{\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">opacity</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">0</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">transform</span>:<span class=\"hljs-value\"> <span class=\"hljs-function\">perspective</span>(<span class=\"hljs-number\">1000px</span>) <span class=\"hljs-function\">rotate3d</span>(<span class=\"hljs-number\">1</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">45deg</span>)</span></span>;\n }</span>\n}\n\n<span class=\"hljs-class\">.custom-enter</span>,\n<span class=\"hljs-class\">.custom-appear</span> <span class=\"hljs-rules\">{\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">opacity</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">0</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">transform</span>:<span class=\"hljs-value\"> <span class=\"hljs-function\">perspective</span>(<span class=\"hljs-number\">1000px</span>) <span class=\"hljs-function\">rotate3d</span>(<span class=\"hljs-number\">1</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">45deg</span>)</span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">transform-origin</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">50%</span> <span class=\"hljs-function\">calc</span>(<span class=\"hljs-number\">100%</span> + <span class=\"hljs-number\">10px</span>)</span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">animation-duration</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">1s</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">animation-fill-mode</span>:<span class=\"hljs-value\"> both</span></span>;\n}</span>\n<span class=\"hljs-class\">.custom-enter-active</span>,\n<span class=\"hljs-class\">.custom-appear-active</span> <span class=\"hljs-rules\">{\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">animation-name</span>:<span class=\"hljs-value\"> flipIn</span></span>;\n}</span>\n\n<span class=\"hljs-class\">.custom-leave</span> <span class=\"hljs-rules\">{\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">opacity</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">1</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">transform</span>:<span class=\"hljs-value\"> <span class=\"hljs-function\">perspective</span>(<span class=\"hljs-number\">1000px</span>) <span class=\"hljs-function\">rotate3d</span>(<span class=\"hljs-number\">1</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">0</span>,<span class=\"hljs-number\">0deg</span>)</span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">animation-duration</span>:<span class=\"hljs-value\"> <span class=\"hljs-number\">1s</span></span></span>;\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">animation-fill-mode</span>:<span class=\"hljs-value\"> both</span></span>;\n}</span>\n\n<span class=\"hljs-class\">.custom-leave-active</span> <span class=\"hljs-rules\">{\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">animation-name</span>:<span class=\"hljs-value\"> flipOut</span></span>;\n}</span></code></pre></div>"},"status":"public","toc":""}]

默认提供的动画样式,只有入场动画。


import { Button } from 'uxcore';
import { Animate } from 'uxcore';
import { Select } from 'uxcore';
const { Option } = Select;

class AwesomeComponent extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <div style={{ display: this.props.visible ? 'inline-block' : 'none' }} className="awesome-component-wrap bg-primary-color">
              动画展示区域
      </div>
    );
  }
}

class Demo extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      visible: true,
      effect: 'fade',
    };
  }

  showComponent() {
    this.setState({
      visible: !this.state.visible,
    });
  }

  handleChange(value) {
    this.setState({
      effect: value,
    });
  }

  render() {
    const effects = ['fade', 'slideRight', 'slideDown', 'newspaper', 'fall', 'threeFallH', 'threeFallV', 'threeSign', 'superScale', 'threeSlit', 'threeRotateBottom', 'threeRotateLeft'];
    return (
      <div>
        <div style={{ height: '60px' }}>
          <Animate showProp="visible" transitionName={this.state.effect} transitionAppear>
            <AwesomeComponent visible={this.state.visible} />
          </Animate>
        </div>
        <div style={{ padding: '10px 0px' }}>
          <Select style={{ width: '200px' }} placeholder="切换动画效果" onChange={this.handleChange.bind(this)} value={this.state.effect}>
            {effects.map(item => <Option key={item}>{item}</Option>)}
          </Select>
          <Button type="outline" onClick={this.showComponent.bind(this)} style={{ marginLeft: '10px' }}>显示/隐藏</Button>
        </div>
      </div>
    );
  }
}

ReactDOM.render(
  <Demo />
, document.getElementById('components-animate-demo-basic'));
.awesome-component-wrap {
    color: white;
    line-height: 40px;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 16px;
}

默认提供的动画样式,只有入场动画。


import { Button } from 'uxcore';
import { Animate } from 'uxcore';
import { Select } from 'uxcore';
const { Option } = Select;

class AwesomeComponent extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <div style={{ display: this.props.visible ? 'inline-block' : 'none' }} className="awesome-component-wrap bg-primary-color">
              动画展示区域
      </div>
    );
  }
}

class Demo extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      visible: true,
    };
  }

  showComponent() {
    this.setState({
      visible: !this.state.visible,
    });
  }

  render() {
    return (
      <div>
        <div style={{ height: '60px' }}>
          <Animate showProp="visible" transitionName={'custom'} transitionAppear onEnd={(key, exists) => {
            console.log(key, exists);
          }}
          >
            <AwesomeComponent key="awesome" visible={this.state.visible} />
          </Animate>
        </div>
        <div style={{ padding: '10px 0px' }}>
          <Button type="outline" onClick={this.showComponent.bind(this)} style={{ marginLeft: '10px' }}>显示/隐藏</Button>
        </div>
      </div>
    );
  }
}

ReactDOM.render(
  <Demo />
, document.getElementById('components-animate-demo-custom'));
.awesome-component-wrap {
    color: white;
    line-height: 40px;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 16px;
}

@keyframes flipIn {
    0% {
        opacity: 0;
        transform: perspective(1000px) rotate3d(1,0,0,45deg);
    }
    100% {
        opacity: 1;
        transform: perspective(1000px) rotate3d(1,0,0,0deg);
    }
}

@keyframes flipOut {
    0% {
        opacity: 1;
        transform: perspective(1000px) rotate3d(1,0,0,0deg);
    }
    100% {
        opacity: 0;
        transform: perspective(1000px) rotate3d(1,0,0,45deg);
    }
}

.custom-enter,
.custom-appear {
    opacity: 0;
    transform: perspective(1000px) rotate3d(1,0,0,45deg);
    transform-origin: 50% calc(100% + 10px);
    animation-duration: 1s;
    animation-fill-mode: both;
}
.custom-enter-active,
.custom-appear-active {
    animation-name: flipIn;
}

.custom-leave {
    opacity: 1;
    transform: perspective(1000px) rotate3d(1,0,0,0deg);
    animation-duration: 1s;
    animation-fill-mode: both;
}

.custom-leave-active {
    animation-name: flipOut;
}

Props

配置项 类型 默认值 功能/备注
component React.Element/String 'span' 使用什么元素或者组件来包裹 children,和 ReactCSSTransitionGroup 类似,如果不想有元素包裹,传 ''
showProp String 指定用于控制显示/隐藏的 prop
transitionName String 和 ReactCSSTransitionGroup 类似,指定对应的 css 名
transitionAppear Boolean false 是否支持 Appear 动画
transitionEnter Boolean true 是否支持 Enter 动画
transitionLeave Boolean true 是否支持 Leave 动画
onEnd function(key, exists) true 动画结束时的回调