move.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import { Keyframes } from '@ant-design/cssinjs';
  2. import { initMotion } from './motion';
  3. export const moveDownIn = new Keyframes('antMoveDownIn', {
  4. '0%': {
  5. transform: 'translate3d(0, 100%, 0)',
  6. transformOrigin: '0 0',
  7. opacity: 0
  8. },
  9. '100%': {
  10. transform: 'translate3d(0, 0, 0)',
  11. transformOrigin: '0 0',
  12. opacity: 1
  13. }
  14. });
  15. export const moveDownOut = new Keyframes('antMoveDownOut', {
  16. '0%': {
  17. transform: 'translate3d(0, 0, 0)',
  18. transformOrigin: '0 0',
  19. opacity: 1
  20. },
  21. '100%': {
  22. transform: 'translate3d(0, 100%, 0)',
  23. transformOrigin: '0 0',
  24. opacity: 0
  25. }
  26. });
  27. export const moveLeftIn = new Keyframes('antMoveLeftIn', {
  28. '0%': {
  29. transform: 'translate3d(-100%, 0, 0)',
  30. transformOrigin: '0 0',
  31. opacity: 0
  32. },
  33. '100%': {
  34. transform: 'translate3d(0, 0, 0)',
  35. transformOrigin: '0 0',
  36. opacity: 1
  37. }
  38. });
  39. export const moveLeftOut = new Keyframes('antMoveLeftOut', {
  40. '0%': {
  41. transform: 'translate3d(0, 0, 0)',
  42. transformOrigin: '0 0',
  43. opacity: 1
  44. },
  45. '100%': {
  46. transform: 'translate3d(-100%, 0, 0)',
  47. transformOrigin: '0 0',
  48. opacity: 0
  49. }
  50. });
  51. export const moveRightIn = new Keyframes('antMoveRightIn', {
  52. '0%': {
  53. transform: 'translate3d(100%, 0, 0)',
  54. transformOrigin: '0 0',
  55. opacity: 0
  56. },
  57. '100%': {
  58. transform: 'translate3d(0, 0, 0)',
  59. transformOrigin: '0 0',
  60. opacity: 1
  61. }
  62. });
  63. export const moveRightOut = new Keyframes('antMoveRightOut', {
  64. '0%': {
  65. transform: 'translate3d(0, 0, 0)',
  66. transformOrigin: '0 0',
  67. opacity: 1
  68. },
  69. '100%': {
  70. transform: 'translate3d(100%, 0, 0)',
  71. transformOrigin: '0 0',
  72. opacity: 0
  73. }
  74. });
  75. export const moveUpIn = new Keyframes('antMoveUpIn', {
  76. '0%': {
  77. transform: 'translate3d(0, -100%, 0)',
  78. transformOrigin: '0 0',
  79. opacity: 0
  80. },
  81. '100%': {
  82. transform: 'translate3d(0, 0, 0)',
  83. transformOrigin: '0 0',
  84. opacity: 1
  85. }
  86. });
  87. export const moveUpOut = new Keyframes('antMoveUpOut', {
  88. '0%': {
  89. transform: 'translate3d(0, 0, 0)',
  90. transformOrigin: '0 0',
  91. opacity: 1
  92. },
  93. '100%': {
  94. transform: 'translate3d(0, -100%, 0)',
  95. transformOrigin: '0 0',
  96. opacity: 0
  97. }
  98. });
  99. const moveMotion = {
  100. 'move-up': {
  101. inKeyframes: moveUpIn,
  102. outKeyframes: moveUpOut
  103. },
  104. 'move-down': {
  105. inKeyframes: moveDownIn,
  106. outKeyframes: moveDownOut
  107. },
  108. 'move-left': {
  109. inKeyframes: moveLeftIn,
  110. outKeyframes: moveLeftOut
  111. },
  112. 'move-right': {
  113. inKeyframes: moveRightIn,
  114. outKeyframes: moveRightOut
  115. }
  116. };
  117. export const initMoveMotion = (token, motionName) => {
  118. const {
  119. antCls
  120. } = token;
  121. const motionCls = `${antCls}-${motionName}`;
  122. const {
  123. inKeyframes,
  124. outKeyframes
  125. } = moveMotion[motionName];
  126. return [initMotion(motionCls, inKeyframes, outKeyframes, token.motionDurationMid), {
  127. [`
  128. ${motionCls}-enter,
  129. ${motionCls}-appear
  130. `]: {
  131. opacity: 0,
  132. animationTimingFunction: token.motionEaseOutCirc
  133. },
  134. [`${motionCls}-leave`]: {
  135. animationTimingFunction: token.motionEaseInOutCirc
  136. }
  137. }];
  138. };