Loading 加载

如果项目中使用的是 1.x 版本的基础组件(@alifd/next),请在左侧导航顶部切换组件版本。

安装方法

  1. 在命令行中执行以下命令npm install @icedesign/base@latest -S

开发指南

何时使用

页面局部处于等待异步数据或正在渲染过程时,合适的加载动效会有效缓解用户的焦虑。

注意事项

Loading 默认使用 display='inline-block' 布局的方式包裹内部元素。

如果希望 通栏包裹 可以修改 <Loading style={{display: 'block'}} />

API

加载

参数说明类型默认值
prefix样式前缀String'next-'
tip自定义内容any-
visibleloading 状态, 默认 trueBoolean-
className自定义classString-
style自定义内联样式Object-
shape动画类型可选值:''(无)'flower'(icon)'fusion-reactor'(fusion矢量)'dot-circle'(点圈)Enum''
color动画颜色String-
children子元素any-

代码示例

基本

最简单的用法。

Loading 加载 - 图1

查看源码在线预览

  1. import { Loading } from "@icedesign/base";
  2. ReactDOM.render(
  3. <Loading tip="加载中...">
  4. <div className="demo">test</div>
  5. </Loading>,
  6. mountNode
  7. );
  1. .demo {
  2. width: 500px;
  3. background-color: #0dcecb;
  4. text-align: center;
  5. padding:50px;
  6. }

加载动画

shape 来区分多种加载动画

Loading 加载 - 图2

查看源码在线预览

  1. import { Loading } from "@icedesign/base";
  2. ReactDOM.render(
  3. <div>
  4. <Loading shape="flower" tip="loading..." color="#333">
  5. <div className="demo">flower</div>
  6. </Loading>
  7. <br />
  8. <Loading shape="fusion-reactor" color="#fff">
  9. <div className="demo">fusion-reactor</div>
  10. </Loading>
  11. <Loading shape="dot-circle">
  12. <div className="demo">dot-circle</div>
  13. </Loading>
  14. </div>,
  15. mountNode
  16. );
  1. .demo {
  2. width: 500px;
  3. background-color: #0dcecb;
  4. text-align: center;
  5. padding:50px;
  6. }
  7. .next-loading {
  8. margin-bottom: 5px;
  9. }

关闭加载

可切换加载状态。

Loading 加载 - 图3

查看源码在线预览

  1. import { Loading, Form, Input, Button } from "@icedesign/base";
  2. const FormItem = Form.Item;
  3. const layout = {
  4. labelCol: {
  5. fixedSpan: 4
  6. },
  7. wrapperCol: {
  8. span: 18
  9. }
  10. };
  11. class App extends React.Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. visible: false
  16. };
  17. }
  18. setVisible(visible) {
  19. this.setState({
  20. visible
  21. });
  22. }
  23. render() {
  24. return (
  25. <div>
  26. <Loading visible={this.state.visible} shape="fusion-reactor">
  27. <Form style={{ width: 500 }}>
  28. <FormItem label="用户名:" {...layout}>
  29. <Input />
  30. </FormItem>
  31. <FormItem label="密码:" {...layout}>
  32. <Input htmlType="password" placeholder="请输入密码" />
  33. </FormItem>
  34. <FormItem label="备注:" {...layout}>
  35. <Input multiple />
  36. </FormItem>
  37. </Form>
  38. </Loading>
  39. <div style={{ paddingLeft: 100 }}>
  40. <Button onClick={this.setVisible.bind(this, true)} type="primary">
  41. 提交
  42. </Button>
  43. <Button onClick={this.setVisible.bind(this, false)}>取消</Button>
  44. </div>
  45. </div>
  46. );
  47. }
  48. }
  49. ReactDOM.render(<App />, mountNode);

自定义

你可以自定义动画,把自己的动画元素传进去, 需要自己写动画样式

Loading 加载 - 图4

查看源码在线预览

  1. import { Loading } from "@icedesign/base";
  2. const tipLoader1 = (
  3. <div className="load-container load1">
  4. <div className="loader">loading...</div>
  5. </div>
  6. );
  7. const tipLoader7 = (
  8. <div className="load-container load7">
  9. <div className="loader">loading...</div>
  10. </div>
  11. );
  12. ReactDOM.render(
  13. <div>
  14. <Loading tip={tipLoader1}>
  15. <div className="demo">test</div>
  16. </Loading>
  17. <Loading tip={tipLoader7}>
  18. <div className="demo">test</div>
  19. </Loading>
  20. </div>,
  21. mountNode
  22. );
  1. .demo {
  2. width: 500px;
  3. background-color: #0dcecb;
  4. text-align: center;
  5. padding:50px;
  6. }
  7. .next-loading {
  8. margin-bottom: 5px;
  9. }
  10. /* css 从这里开始抄 */
  11. .load-container {
  12. margin: 0 auto;
  13. position: relative;
  14. }
  15. /* 第一个动画效果 */
  16. .load1 .loader,
  17. .load1 .loader:before,
  18. .load1 .loader:after {
  19. background: #fff;
  20. color: #fff;
  21. -webkit-animation: load1 1s infinite ease-in-out;
  22. animation: load1 1s infinite ease-in-out;
  23. width: 1em;
  24. height: 4em;
  25. }
  26. .load1 .loader:before,
  27. .load1 .loader:after {
  28. position: absolute;
  29. top: 0;
  30. content: '';
  31. }
  32. .load1 .loader:before {
  33. left: -1.5em;
  34. -webkit-animation-delay: -0.32s;
  35. animation-delay: -0.32s;
  36. }
  37. .load1 .loader {
  38. text-indent: -9999em;
  39. margin: 0 auto !important;
  40. position: relative;
  41. font-size: 11px;
  42. -webkit-animation-delay: -0.16s;
  43. animation-delay: -0.16s;
  44. }
  45. .load1 .loader:after {
  46. left: 1.5em;
  47. }
  48. @-webkit-keyframes load1 {
  49. 0%,
  50. 80%,
  51. 100% {
  52. box-shadow: 0 0 ;
  53. height: 4em;
  54. }
  55. 40% {
  56. box-shadow: 0 -2em ;
  57. height: 5em;
  58. }
  59. }
  60. @keyframes load1 {
  61. 0%,
  62. 80%,
  63. 100% {
  64. box-shadow: 0 0 ;
  65. height: 4em;
  66. }
  67. 40% {
  68. box-shadow: 0 -2em ;
  69. height: 5em;
  70. }
  71. }
  72. /* 第二个动画效果 */
  73. .load7 .loader:before,
  74. .load7 .loader:after,
  75. .load7 .loader {
  76. border-radius: 50%;
  77. width: 2.5em;
  78. height: 2.5em;
  79. -webkit-animation-fill-mode: both;
  80. animation-fill-mode: both;
  81. -webkit-animation: load7 1.8s infinite ease-in-out;
  82. animation: load7 1.8s infinite ease-in-out;
  83. top: -36px;
  84. }
  85. .load7 .loader {
  86. margin: 0 auto !important;
  87. font-size: 10px;
  88. position: relative;
  89. text-indent: -9999em;
  90. -webkit-animation-delay: -0.16s;
  91. animation-delay: -0.16s;
  92. }
  93. .load7 .loader:before {
  94. left: -3.5em;
  95. -webkit-animation-delay: -0.32s;
  96. animation-delay: -0.32s;
  97. }
  98. .load7 .loader:after {
  99. left: 3.5em;
  100. }
  101. .load7 .loader:before,
  102. .load7 .loader:after {
  103. content: '';
  104. position: absolute;
  105. top: 0;
  106. }
  107. @-webkit-keyframes load7 {
  108. 0%,
  109. 80%,
  110. 100% {
  111. box-shadow: 0 2.5em 0 -1.3em #fff;
  112. }
  113. 40% {
  114. box-shadow: 0 2.5em 0 0 #fff;
  115. }
  116. }
  117. @keyframes load7 {
  118. 0%,
  119. 80%,
  120. 100% {
  121. box-shadow: 0 2.5em 0 -1.3em #fff;
  122. }
  123. 40% {
  124. box-shadow: 0 2.5em 0 0 #fff;
  125. }
  126. }

相关区块

Loading 加载 - 图5

暂无相关区块