b79fa4887dc1e4e3040302952ffc58f244b8b2ba8d3be37255f122bf68877ccb4eb00add7f2dce7b7d320588d4b9dbb4e93e451c2df25f5e70ffb281be75b4 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. [ENGLISH](./README_EN.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="NPM" /></a>
  7. </p>
  8. ### Transition是什么?
  9. - 它是一个基于**贝塞尔曲线**的动效插件。
  10. - 它提供常用的**缓动曲线**。
  11. - 支持**自定义**缓动曲线。
  12. ### 动画是如何产生的?
  13. * 获取一帧动画数据
  14. * 根据动画数据渲染图像
  15. * 重复...
  16. 我们可以使用三组数据去描述一段动画(**动画起始状态**、**动画结束状态**、**缓动曲线**),根据这三组数据我们可以计算出动画过程中每一帧动画的状态。这就是***Transition***所提供的功能,根据每一帧动画的状态,我们不断的进行重绘,动画就产生了。
  17. ### npm安装
  18. ```shell
  19. $ npm install @jiaminghi/transition
  20. ```
  21. ### 使用
  22. ```javascript
  23. import { transition, injectNewCurve } from '@jiaminghi/transition'
  24. // do something
  25. ```
  26. ### 快速体验
  27. ```html
  28. <!--资源位于个人服务器仅供体验和测试,请勿在生产环境使用-->
  29. <!--调试版-->
  30. <script src="http://lib.jiaminghi.com/transition/transition.map.js"></script>
  31. <!--压缩版-->
  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. 详细文档及示例请移步[HomePage](http://transition.jiaminghi.com).
  39. - [注解](#注解)
  40. - [示例](#示例)
  41. - [扩展新曲线](#扩展新曲线)
  42. - [缓动曲线表](#缓动曲线表)
  43. ------
  44. <h3 align="center">注解</h3>
  45. ```javascript
  46. /**
  47. * @description 根据动画起止状态及缓动曲线获取若干帧动画状态数据
  48. * @param {String|Array} tBC 缓动曲线名称或曲线数据
  49. * @param {Number|Arrya|Object} startState 动画起始状态
  50. * @param {Number|Arrya|Object} endState 动画结束状态
  51. * @param {Number} frameNum 动画帧数
  52. * @param {Boolean} deep 是否启用递归模式
  53. * @return {Array} 每一帧的动画数据
  54. */
  55. function transition (tBC, startState = null, endState = null, frameNum = 30, deep = false) { // ...
  56. }
  57. ```
  58. <h3 align="center">示例</h3>
  59. **Transition** 支持三种数据类型以描述动画状态.
  60. * [Number](#Number)
  61. * [Array](#Array)
  62. * [Object](#Annotation)
  63. * [Recursive](#Recursive)
  64. #### Number
  65. ```javascript
  66. import transition from '@jiaminghi/transition'
  67. const beginState = 0
  68. const endState = 100
  69. const animationState = transition('linear', beginState, endState, 10)
  70. /**
  71. * animationState = [
  72. * 0, 11.03429355281208, 22.126200274348417, 33.259259259259245, 44.41700960219478,
  73. * 55.58299039780521, 66.74074074074073, 77.87379972565157, 88.96570644718793, 100
  74. * ]
  75. * /
  76. ```
  77. #### Array
  78. ```javascript
  79. import transition from '@jiaminghi/transition'
  80. const beginState = [10, 20, 30]
  81. const endState = [100, 200, 300]
  82. const animationState = transition('linear', beginState, endState, 10)
  83. /**
  84. * animationState = [
  85. * [10, 20, 30],
  86. * [32.415625, 64.83125, 97.24687499999999],
  87. * [55, 110, 165],
  88. * [77.58437500000001, 155.16875000000002, 232.753125],
  89. * [100, 200, 300]
  90. * ]
  91. * /
  92. ```
  93. #### Object
  94. ```javascript
  95. import transition from '@jiaminghi/transition'
  96. const objectBeginState = { x: 10, y: 10, r: 5}
  97. const objectEndState = { x: 100, y: 10, r: 5}
  98. const animationState = transition('linear', objectBeginState, objectEndState, 5)
  99. /**
  100. * animationState = [
  101. * {x: 10, y: 10, r: 5},
  102. * {x: 32.415625, y: 10, r: 5},
  103. * {x: 55, y: 10, r: 5},
  104. * {x: 77.58437500000001, y: 10, r: 5},
  105. * {x: 100, y: 10, r: 5}
  106. * ]
  107. * /
  108. ```
  109. #### Recursive
  110. 启用递归模式以计算`Array`或`Object`中的深层数据.
  111. ```javascript
  112. import transition from '@jiaminghi/transition'
  113. const beginState = {
  114. points: [ [10, 30], [20, 80] ],
  115. origin: { x: 10, y: 20 },
  116. radius: 3
  117. }
  118. const endState = {
  119. points: [ [100, 230], [120, 10] ],
  120. origin: { x: 100, y: 200 },
  121. radius: 9
  122. }
  123. const animationState = transition('linear', beginState, endState, 3, true)
  124. /**
  125. * animationState = [
  126. * {
  127. * origin: { x: 10, y: 20 },
  128. * points: [ [10, 30], [20, 80] ],
  129. * radius: 3
  130. * },
  131. * {
  132. * origin: { x: 55, y: 110 },
  133. * points: [ [55, 130], [70, 45] ],
  134. * radius: 6
  135. * },
  136. * {
  137. * origin: { x: 100, y: 200 },
  138. * points: [ [100, 230], [120, 10] ],
  139. * radius: 9
  140. * }
  141. * ]
  142. * /
  143. ```
  144. **Notice**
  145. * 非数值的属性或元素不参与计算过程.
  146. * 起始状态与结束状态的数据类型(包括属性及元素的数量)必须保持一致.
  147. <h3 align="center">扩展新曲线</h3>
  148. 如果你想扩展新的缓动曲线,你可以使用`Transition`提供的`injectNewCurve`方法去扩展。
  149. ```javascript
  150. import { injectNewCurve } from '@jiaminghi/transition'
  151. const curveName = 'linear'
  152. // 可以使用绘制工具获得
  153. const bezierCurve = [[[0, 1]],[[1, 0]]]
  154. injectNewCurve(curveName, bezierCurve)
  155. ```
  156. [缓动曲线绘制工具](http://transition.jiaminghi.com/draw/)
  157. <h3 align="center">缓动曲线表</h3>
  158. * [linear](#linear)
  159. * [easeInSine](#easeInSine)
  160. * [easeOutSine](#easeOutSine)
  161. * [easeInOutSine](#easeInOutSine)
  162. * [easeInQuad](#easeInQuad)
  163. * [easeOutQuad](#easeOutQuad)
  164. * [easeInOutQuad](#easeInOutQuad)
  165. * [easeInCubic](#easeInCubic)
  166. * [easeOutCubic](#easeOutCubic)
  167. * [easeInOutCubic](#easeInOutCubic)
  168. * [easeInQuart](#easeInQuart)
  169. * [easeOutQuart](#easeOutQuart)
  170. * [easeInOutQuart](#easeInOutQuart)
  171. * [easeInQuint](#easeInQuint)
  172. * [easeOutQuint](#easeOutQuint)
  173. * [easeInOutQuint](#easeInOutQuint)
  174. * [easeInBack](#easeInBack)
  175. * [easeOutBack](#easeOutBack)
  176. * [easeInOutBack](#easeInOutBack)
  177. * [easeInElastic](#easeInElastic)
  178. * [easeOutElastic](#easeOutElastic)
  179. * [easeInOutElastic](#easeInOutElastic)
  180. * [easeInBounce](#easeInBounce)
  181. * [easeOutBounce](#easeOutBounce)
  182. * [easeInOutBounce](#easeInOutBounce)
  183. #### linear
  184. ![linear](/exampleImg/linear.gif)
  185. #### easeInSine
  186. ![linear](/exampleImg/easeInSine.gif)
  187. #### easeOutSine
  188. ![linear](/exampleImg/easeOutSine.gif)
  189. #### easeInOutSine
  190. ![linear](/exampleImg/easeInOutSine.gif)
  191. #### easeInQuad
  192. ![linear](/exampleImg/easeInQuad.gif)
  193. #### easeOutQuad
  194. ![linear](/exampleImg/easeOutQuad.gif)
  195. #### easeInOutQuad
  196. ![linear](/exampleImg/easeInOutQuad.gif)
  197. #### easeInCubic
  198. ![linear](/exampleImg/easeInCubic.gif)
  199. #### easeOutCubic
  200. ![linear](/exampleImg/easeOutCubic.gif)
  201. #### easeInOutCubic
  202. ![linear](/exampleImg/easeInOutCubic.gif)
  203. #### easeInQuart
  204. ![linear](/exampleImg/easeInQuart.gif)
  205. #### easeOutQuart
  206. ![linear](/exampleImg/easeOutQuart.gif)
  207. #### easeInOutQuart
  208. ![linear](/exampleImg/easeInOutQuart.gif)
  209. #### easeInQuint
  210. ![linear](/exampleImg/easeInQuint.gif)
  211. #### easeOutQuint
  212. ![linear](/exampleImg/easeOutQuint.gif)
  213. #### easeInOutQuint
  214. ![linear](/exampleImg/easeInOutQuint.gif)
  215. #### easeInBack
  216. ![linear](/exampleImg/easeInBack.gif)
  217. #### easeOutBack
  218. ![linear](/exampleImg/easeOutBack.gif)
  219. #### easeInOutBack
  220. ![linear](/exampleImg/easeInOutBack.gif)
  221. #### easeInElastic
  222. ![linear](/exampleImg/easeInElastic.gif)
  223. #### easeOutElastic
  224. ![linear](/exampleImg/easeOutElastic.gif)
  225. #### easeInOutElastic
  226. ![linear](/exampleImg/easeInOutElastic.gif)
  227. #### easeInBounce
  228. ![linear](/exampleImg/easeInBounce.gif)
  229. #### easeOutBounce
  230. ![linear](/exampleImg/easeOutBounce.gif)
  231. #### easeInOutBounce
  232. ![linear](/exampleImg/easeInOutBounce.gif)