slide.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { Keyframes } from '@ant-design/cssinjs';
  2. import { initMotion } from './motion';
  3. export const slideUpIn = new Keyframes('antSlideUpIn', {
  4. '0%': {
  5. transform: 'scaleY(0.8)',
  6. transformOrigin: '0% 0%',
  7. opacity: 0
  8. },
  9. '100%': {
  10. transform: 'scaleY(1)',
  11. transformOrigin: '0% 0%',
  12. opacity: 1
  13. }
  14. });
  15. export const slideUpOut = new Keyframes('antSlideUpOut', {
  16. '0%': {
  17. transform: 'scaleY(1)',
  18. transformOrigin: '0% 0%',
  19. opacity: 1
  20. },
  21. '100%': {
  22. transform: 'scaleY(0.8)',
  23. transformOrigin: '0% 0%',
  24. opacity: 0
  25. }
  26. });
  27. export const slideDownIn = new Keyframes('antSlideDownIn', {
  28. '0%': {
  29. transform: 'scaleY(0.8)',
  30. transformOrigin: '100% 100%',
  31. opacity: 0
  32. },
  33. '100%': {
  34. transform: 'scaleY(1)',
  35. transformOrigin: '100% 100%',
  36. opacity: 1
  37. }
  38. });
  39. export const slideDownOut = new Keyframes('antSlideDownOut', {
  40. '0%': {
  41. transform: 'scaleY(1)',
  42. transformOrigin: '100% 100%',
  43. opacity: 1
  44. },
  45. '100%': {
  46. transform: 'scaleY(0.8)',
  47. transformOrigin: '100% 100%',
  48. opacity: 0
  49. }
  50. });
  51. export const slideLeftIn = new Keyframes('antSlideLeftIn', {
  52. '0%': {
  53. transform: 'scaleX(0.8)',
  54. transformOrigin: '0% 0%',
  55. opacity: 0
  56. },
  57. '100%': {
  58. transform: 'scaleX(1)',
  59. transformOrigin: '0% 0%',
  60. opacity: 1
  61. }
  62. });
  63. export const slideLeftOut = new Keyframes('antSlideLeftOut', {
  64. '0%': {
  65. transform: 'scaleX(1)',
  66. transformOrigin: '0% 0%',
  67. opacity: 1
  68. },
  69. '100%': {
  70. transform: 'scaleX(0.8)',
  71. transformOrigin: '0% 0%',
  72. opacity: 0
  73. }
  74. });
  75. export const slideRightIn = new Keyframes('antSlideRightIn', {
  76. '0%': {
  77. transform: 'scaleX(0.8)',
  78. transformOrigin: '100% 0%',
  79. opacity: 0
  80. },
  81. '100%': {
  82. transform: 'scaleX(1)',
  83. transformOrigin: '100% 0%',
  84. opacity: 1
  85. }
  86. });
  87. export const slideRightOut = new Keyframes('antSlideRightOut', {
  88. '0%': {
  89. transform: 'scaleX(1)',
  90. transformOrigin: '100% 0%',
  91. opacity: 1
  92. },
  93. '100%': {
  94. transform: 'scaleX(0.8)',
  95. transformOrigin: '100% 0%',
  96. opacity: 0
  97. }
  98. });
  99. const slideMotion = {
  100. 'slide-up': {
  101. inKeyframes: slideUpIn,
  102. outKeyframes: slideUpOut
  103. },
  104. 'slide-down': {
  105. inKeyframes: slideDownIn,
  106. outKeyframes: slideDownOut
  107. },
  108. 'slide-left': {
  109. inKeyframes: slideLeftIn,
  110. outKeyframes: slideLeftOut
  111. },
  112. 'slide-right': {
  113. inKeyframes: slideRightIn,
  114. outKeyframes: slideRightOut
  115. }
  116. };
  117. export const initSlideMotion = (token, motionName) => {
  118. const {
  119. antCls
  120. } = token;
  121. const motionCls = `${antCls}-${motionName}`;
  122. const {
  123. inKeyframes,
  124. outKeyframes
  125. } = slideMotion[motionName];
  126. return [initMotion(motionCls, inKeyframes, outKeyframes, token.motionDurationMid), {
  127. [`
  128. ${motionCls}-enter,
  129. ${motionCls}-appear
  130. `]: {
  131. transform: 'scale(0)',
  132. transformOrigin: '0% 0%',
  133. opacity: 0,
  134. animationTimingFunction: token.motionEaseOutQuint,
  135. '&-prepare': {
  136. transform: 'scale(1)'
  137. }
  138. },
  139. [`${motionCls}-leave`]: {
  140. animationTimingFunction: token.motionEaseInQuint
  141. }
  142. }];
  143. };