zoom.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { Keyframes } from '@ant-design/cssinjs';
  2. import { initMotion } from './motion';
  3. export const zoomIn = new Keyframes('antZoomIn', {
  4. '0%': {
  5. transform: 'scale(0.2)',
  6. opacity: 0
  7. },
  8. '100%': {
  9. transform: 'scale(1)',
  10. opacity: 1
  11. }
  12. });
  13. export const zoomOut = new Keyframes('antZoomOut', {
  14. '0%': {
  15. transform: 'scale(1)'
  16. },
  17. '100%': {
  18. transform: 'scale(0.2)',
  19. opacity: 0
  20. }
  21. });
  22. export const zoomBigIn = new Keyframes('antZoomBigIn', {
  23. '0%': {
  24. transform: 'scale(0.8)',
  25. opacity: 0
  26. },
  27. '100%': {
  28. transform: 'scale(1)',
  29. opacity: 1
  30. }
  31. });
  32. export const zoomBigOut = new Keyframes('antZoomBigOut', {
  33. '0%': {
  34. transform: 'scale(1)'
  35. },
  36. '100%': {
  37. transform: 'scale(0.8)',
  38. opacity: 0
  39. }
  40. });
  41. export const zoomUpIn = new Keyframes('antZoomUpIn', {
  42. '0%': {
  43. transform: 'scale(0.8)',
  44. transformOrigin: '50% 0%',
  45. opacity: 0
  46. },
  47. '100%': {
  48. transform: 'scale(1)',
  49. transformOrigin: '50% 0%'
  50. }
  51. });
  52. export const zoomUpOut = new Keyframes('antZoomUpOut', {
  53. '0%': {
  54. transform: 'scale(1)',
  55. transformOrigin: '50% 0%'
  56. },
  57. '100%': {
  58. transform: 'scale(0.8)',
  59. transformOrigin: '50% 0%',
  60. opacity: 0
  61. }
  62. });
  63. export const zoomLeftIn = new Keyframes('antZoomLeftIn', {
  64. '0%': {
  65. transform: 'scale(0.8)',
  66. transformOrigin: '0% 50%',
  67. opacity: 0
  68. },
  69. '100%': {
  70. transform: 'scale(1)',
  71. transformOrigin: '0% 50%'
  72. }
  73. });
  74. export const zoomLeftOut = new Keyframes('antZoomLeftOut', {
  75. '0%': {
  76. transform: 'scale(1)',
  77. transformOrigin: '0% 50%'
  78. },
  79. '100%': {
  80. transform: 'scale(0.8)',
  81. transformOrigin: '0% 50%',
  82. opacity: 0
  83. }
  84. });
  85. export const zoomRightIn = new Keyframes('antZoomRightIn', {
  86. '0%': {
  87. transform: 'scale(0.8)',
  88. transformOrigin: '100% 50%',
  89. opacity: 0
  90. },
  91. '100%': {
  92. transform: 'scale(1)',
  93. transformOrigin: '100% 50%'
  94. }
  95. });
  96. export const zoomRightOut = new Keyframes('antZoomRightOut', {
  97. '0%': {
  98. transform: 'scale(1)',
  99. transformOrigin: '100% 50%'
  100. },
  101. '100%': {
  102. transform: 'scale(0.8)',
  103. transformOrigin: '100% 50%',
  104. opacity: 0
  105. }
  106. });
  107. export const zoomDownIn = new Keyframes('antZoomDownIn', {
  108. '0%': {
  109. transform: 'scale(0.8)',
  110. transformOrigin: '50% 100%',
  111. opacity: 0
  112. },
  113. '100%': {
  114. transform: 'scale(1)',
  115. transformOrigin: '50% 100%'
  116. }
  117. });
  118. export const zoomDownOut = new Keyframes('antZoomDownOut', {
  119. '0%': {
  120. transform: 'scale(1)',
  121. transformOrigin: '50% 100%'
  122. },
  123. '100%': {
  124. transform: 'scale(0.8)',
  125. transformOrigin: '50% 100%',
  126. opacity: 0
  127. }
  128. });
  129. const zoomMotion = {
  130. zoom: {
  131. inKeyframes: zoomIn,
  132. outKeyframes: zoomOut
  133. },
  134. 'zoom-big': {
  135. inKeyframes: zoomBigIn,
  136. outKeyframes: zoomBigOut
  137. },
  138. 'zoom-big-fast': {
  139. inKeyframes: zoomBigIn,
  140. outKeyframes: zoomBigOut
  141. },
  142. 'zoom-left': {
  143. inKeyframes: zoomLeftIn,
  144. outKeyframes: zoomLeftOut
  145. },
  146. 'zoom-right': {
  147. inKeyframes: zoomRightIn,
  148. outKeyframes: zoomRightOut
  149. },
  150. 'zoom-up': {
  151. inKeyframes: zoomUpIn,
  152. outKeyframes: zoomUpOut
  153. },
  154. 'zoom-down': {
  155. inKeyframes: zoomDownIn,
  156. outKeyframes: zoomDownOut
  157. }
  158. };
  159. export const initZoomMotion = (token, motionName) => {
  160. const {
  161. antCls
  162. } = token;
  163. const motionCls = `${antCls}-${motionName}`;
  164. const {
  165. inKeyframes,
  166. outKeyframes
  167. } = zoomMotion[motionName];
  168. return [initMotion(motionCls, inKeyframes, outKeyframes, motionName === 'zoom-big-fast' ? token.motionDurationFast : token.motionDurationMid), {
  169. [`
  170. ${motionCls}-enter,
  171. ${motionCls}-appear
  172. `]: {
  173. transform: 'scale(0)',
  174. opacity: 0,
  175. animationTimingFunction: token.motionEaseOutCirc,
  176. '&-prepare': {
  177. transform: 'none'
  178. }
  179. },
  180. [`${motionCls}-leave`]: {
  181. animationTimingFunction: token.motionEaseInOutCirc
  182. }
  183. }];
  184. };