a85f64fdb75efffc0ed1b401051f7a4b6d2128f0a11e48faea4696128a31fe4d3c24eba9e68fc456ce7514b50ed4f3e4460731d26bb051c9c9e287ad1f4201 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. [中文](./README.md)
  2. <h1 align="center">Transition</h1>
  3. <p align="center">
  4. <a href="https://travis-ci.com/jiaming743/transition"><img src="https://img.shields.io/travis/com/jiaming743/transition.svg" alt="Travis CI"></a>
  5. <a href="https://github.com/jiaming743/transition/blob/master/LICENSE"><img src="https://img.shields.io/github/license/jiaming743/transition.svg" alt="LICENSE" /> </a>
  6. <a href="https://www.npmjs.com/package/@jiaminghi/transition"><img src="https://img.shields.io/npm/v/@jiaminghi/transition.svg" alt="LICENSE" /> </a>
  7. </p>
  8. ### What is Transition?
  9. - It is a dynamic effect plugin based on **Bezier Curve**.
  10. - It provides common **easing** curve.
  11. - **Customizable** easing curve.
  12. ### How is the animation produced?
  13. * Get one frame data of the animation.
  14. * Draw this frame animation.
  15. * Repeat...
  16. We can use three sets of data to describe an animation (**animation start state**, **animation end state**, **easing curve**).Based on these three sets of data, we can calculate the **state of each frame** of the animation,this is what ***Transition*** provided.According to the data of each frame, we carry out continuous redrawing, and the animation is generated.
  17. ### Install with npm
  18. ```shell
  19. $ npm install @jiaminghi/transition
  20. ```
  21. ### Use
  22. ```javascript
  23. import { transition, injectNewCurve } from '@jiaminghi/transition'
  24. // do something
  25. ```
  26. ### Quick experience
  27. ```html
  28. <!--Resources are located on personal servers for experience and testing only, do not use in production environments-->
  29. <!--Debug version-->
  30. <script src="http://lib.jiaminghi.com/transition/transition.map.js"></script>
  31. <!--Compression version-->
  32. <script src="http://lib.jiaminghi.com/transition/transition.min.js"></script>
  33. <script>
  34. const { transition, injectNewCurve } = window.transition
  35. // do something
  36. </script>
  37. ```
  38. Detailed documents and examples can be viewed on the [HomePage](http://transition.jiaminghi.com/EN/).
  39. - [Annotation](#Annotation)
  40. - [Examples](#examples)
  41. - [Extend New Easing Curve](#Extend-New-Easing-Curve)
  42. - [Easing Curve Table](#Easing-curve-table)
  43. ------
  44. <h3 align="center">Annotation</h3>
  45. ```javascript
  46. /**
  47. * @description Get the N-frame animation state by the start and end state
  48. * of the animation and the easing curve
  49. * @param {String|Array} tBC Easing curve name or data
  50. * @param {Number|Arrya|Object} startState Animation start state
  51. * @param {Number|Arrya|Object} endState Animation end state
  52. * @param {Number} frameNum Number of Animation frames
  53. * @param {Boolean} deep Whether to use recursive mode
  54. * @return {Array} State of each frame of the animation
  55. */
  56. function transition (tBC, startState = false, endState = false, frameNum = 30, deep = false) { // ...
  57. }
  58. ```
  59. <h3 align="center">Examples</h3>
  60. **Transition** provides three data types to describe the animation state.
  61. * [Number](#Number)
  62. * [Array](#Array)
  63. * [Object](#Annotation)
  64. * [Recursive](#Recursive)
  65. #### Number
  66. ```javascript
  67. import transition from '@jiaminghi/transition'
  68. const beginState = 0
  69. const endState = 100
  70. const animationState = transition('linear', beginState, endState, 10)
  71. /**
  72. * animationState = [
  73. * 0, 11.03429355281208, 22.126200274348417, 33.259259259259245, 44.41700960219478,
  74. * 55.58299039780521, 66.74074074074073, 77.87379972565157, 88.96570644718793, 100
  75. * ]
  76. * /
  77. ```
  78. #### Array
  79. ```javascript
  80. import transition from '@jiaminghi/transition'
  81. const beginState = [10, 20, 30]
  82. const endState = [100, 200, 300]
  83. const animationState = transition('linear', beginState, endState, 10)
  84. /**
  85. * animationState = [
  86. * [10, 20, 30],
  87. * [32.415625, 64.83125, 97.24687499999999],
  88. * [55, 110, 165],
  89. * [77.58437500000001, 155.16875000000002, 232.753125],
  90. * [100, 200, 300]
  91. * ]
  92. * /
  93. ```
  94. #### Object
  95. ```javascript
  96. import transition from '@jiaminghi/transition'
  97. const objectBeginState = { x: 10, y: 10, r: 5}
  98. const objectEndState = { x: 100, y: 10, r: 5}
  99. const animationState = transition('linear', objectBeginState, objectEndState, 5)
  100. /**
  101. * animationState = [
  102. * {x: 10, y: 10, r: 5},
  103. * {x: 32.415625, y: 10, r: 5},
  104. * {x: 55, y: 10, r: 5},
  105. * {x: 77.58437500000001, y: 10, r: 5},
  106. * {x: 100, y: 10, r: 5}
  107. * ]
  108. * /
  109. ```
  110. #### Recursive
  111. Use recursive mode to calculate deep data in `Array` or `Object`.
  112. ```javascript
  113. import transition from '@jiaminghi/transition'
  114. const beginState = {
  115. points: [ [10, 30], [20, 80] ],
  116. origin: { x: 10, y: 20 },
  117. radius: 3
  118. }
  119. const endState = {
  120. points: [ [100, 230], [120, 10] ],
  121. origin: { x: 100, y: 200 },
  122. radius: 9
  123. }
  124. const animationState = transition('linear', beginState, endState, 3, true)
  125. /**
  126. * animationState = [
  127. * {
  128. * origin: { x: 10, y: 20 },
  129. * points: [ [10, 30], [20, 80] ],
  130. * radius: 3
  131. * },
  132. * {
  133. * origin: { x: 55, y: 110 },
  134. * points: [ [55, 130], [70, 45] ],
  135. * radius: 6
  136. * },
  137. * {
  138. * origin: { x: 100, y: 200 },
  139. * points: [ [100, 230], [120, 10] ],
  140. * radius: 9
  141. * }
  142. * ]
  143. * /
  144. ```
  145. **Notice**
  146. * Non-Number attribute or element does not participate in calculations.
  147. * The data type of the start and end state should be consistent(Including the number of attributes and elements).
  148. <h3 align="center">Extend New Easing Curve</h3>
  149. If you want to extend the new **easing curve**, you can use the `injectNewCurve` method provided by `Transition` to extend.
  150. ```javascript
  151. import { injectNewCurve } from '@jiaminghi/transition'
  152. const curveName = 'linear'
  153. // Can be obtained by drawing tools
  154. const bezierCurve = [[[0, 1]],[[1, 0]]]
  155. injectNewCurve(curveName, bezierCurve)
  156. ```
  157. [Easing curve drawing tool](http://transition.jiaminghi.com/EN/draw/)
  158. <h3 align="center">Easing Curve Table</h3>
  159. * [linear](#linear)
  160. * [easeInSine](#easeInSine)
  161. * [easeOutSine](#easeOutSine)
  162. * [easeInOutSine](#easeInOutSine)
  163. * [easeInQuad](#easeInQuad)
  164. * [easeOutQuad](#easeOutQuad)
  165. * [easeInOutQuad](#easeInOutQuad)
  166. * [easeInCubic](#easeInCubic)
  167. * [easeOutCubic](#easeOutCubic)
  168. * [easeInOutCubic](#easeInOutCubic)
  169. * [easeInQuart](#easeInQuart)
  170. * [easeOutQuart](#easeOutQuart)
  171. * [easeInOutQuart](#easeInOutQuart)
  172. * [easeInQuint](#easeInQuint)
  173. * [easeOutQuint](#easeOutQuint)
  174. * [easeInOutQuint](#easeInOutQuint)
  175. * [easeInBack](#easeInBack)
  176. * [easeOutBack](#easeOutBack)
  177. * [easeInOutBack](#easeInOutBack)
  178. * [easeInElastic](#easeInElastic)
  179. * [easeOutElastic](#easeOutElastic)
  180. * [easeInOutElastic](#easeInOutElastic)
  181. * [easeInBounce](#easeInBounce)
  182. * [easeOutBounce](#easeOutBounce)
  183. * [easeInOutBounce](#easeInOutBounce)
  184. #### linear
  185. ![linear](/exampleImg/linear.gif)
  186. #### easeInSine
  187. ![linear](/exampleImg/easeInSine.gif)
  188. #### easeOutSine
  189. ![linear](/exampleImg/easeOutSine.gif)
  190. #### easeInOutSine
  191. ![linear](/exampleImg/easeInOutSine.gif)
  192. #### easeInQuad
  193. ![linear](/exampleImg/easeInQuad.gif)
  194. #### easeOutQuad
  195. ![linear](/exampleImg/easeOutQuad.gif)
  196. #### easeInOutQuad
  197. ![linear](/exampleImg/easeInOutQuad.gif)
  198. #### easeInCubic
  199. ![linear](/exampleImg/easeInCubic.gif)
  200. #### easeOutCubic
  201. ![linear](/exampleImg/easeOutCubic.gif)
  202. #### easeInOutCubic
  203. ![linear](/exampleImg/easeInOutCubic.gif)
  204. #### easeInQuart
  205. ![linear](/exampleImg/easeInQuart.gif)
  206. #### easeOutQuart
  207. ![linear](/exampleImg/easeOutQuart.gif)
  208. #### easeInOutQuart
  209. ![linear](/exampleImg/easeInOutQuart.gif)
  210. #### easeInQuint
  211. ![linear](/exampleImg/easeInQuint.gif)
  212. #### easeOutQuint
  213. ![linear](/exampleImg/easeOutQuint.gif)
  214. #### easeInOutQuint
  215. ![linear](/exampleImg/easeInOutQuint.gif)
  216. #### easeInBack
  217. ![linear](/exampleImg/easeInBack.gif)
  218. #### easeOutBack
  219. ![linear](/exampleImg/easeOutBack.gif)
  220. #### easeInOutBack
  221. ![linear](/exampleImg/easeInOutBack.gif)
  222. #### easeInElastic
  223. ![linear](/exampleImg/easeInElastic.gif)
  224. #### easeOutElastic
  225. ![linear](/exampleImg/easeOutElastic.gif)
  226. #### easeInOutElastic
  227. ![linear](/exampleImg/easeInOutElastic.gif)
  228. #### easeInBounce
  229. ![linear](/exampleImg/easeInBounce.gif)
  230. #### easeOutBounce
  231. ![linear](/exampleImg/easeOutBounce.gif)
  232. #### easeInOutBounce
  233. ![linear](/exampleImg/easeInOutBounce.gif)