从图像序列创建动画 jQuery Animate.js

  • 源码大小:131.55KB
  • 所需积分:1积分
  • 源码编号:19JP-3427
  • 浏览次数:725次
  • 最后更新:2023年06月12日
  • 所属栏目:动画
本站默认解压密码:19jp.com 或 19jp_com

简介

Animate.js是一个很小的jQuery插件,用于从一系列图像中创建可链接的动画。此插件用于将一系列图像组合在一起,以创建GIF风格的动画图像。

它支持fadeIn/fadeOut/Reval动画、自定义图像位置和可配置的动画延迟。通过这种方式,您可以创建简单/高级/可定制的动画,而无需编写任何CSS或JavaScript动画代码。

如何使用它:

1.在jQuery之后加载animate.js。

  1. <script src="/path/to/cdn/jquery.min.js"></script>
  2. <script src="/path/to/js/animate.js"></script>

2.创建一个容器来容纳动画。

  1. <div class="example"></div>

3.将一组动画添加到动画集数组,如下所示。

  1. var options = {
  2.  
  3. // width & height in pixels
  4. 'width': 813,
  5. 'height': 614,
  6.  
  7. // unique ID
  8. 'id': 'jqueryscript',
  9.  
  10. // define your animations here
  11. 'animationSets': [
  12. new Animation([
  13. {
  14. // image source
  15. 'imagesrc': 'images/chart-bg.jpg',
  16. // position
  17. 'position': {
  18. x: 0,
  19. y: 0
  20. },
  21. 'width': 813,
  22. 'height': 614,
  23. }, {
  24. 'imagesrc': 'images/gray-line-1.png',
  25. 'position': {
  26. x: 164,
  27. y: 94
  28. },
  29. 'width': 221,
  30. 'height': 212,
  31. // reveal, fadeIn, or fadeOut
  32. 'type': 'reveal',
  33. // duration in ms
  34. 'duration': 500,
  35. }, {
  36. 'imagesrc': 'images/orange-line-1.png',
  37. 'position': {
  38. x: 164,
  39. y: 90
  40. },
  41. 'width': 221,
  42. 'height': 125,
  43. 'type': 'reveal',
  44. 'duration': 2000,
  45. // delay in ms
  46. 'delay': 1000
  47. }
  48. ]),
  49. new Animation([
  50. {
  51. 'imagesrc': 'images/orange-explanation.png',
  52. 'position': {
  53. x: 634,
  54. y: 150
  55. },
  56. 'width': 179,
  57. 'height': 100,
  58. 'type': 'fadeIn',
  59. 'duration': 500,
  60. // unique ID
  61. 'id': 'fadeout-2',
  62. 'delay': 100
  63. }, {
  64. 'imagesrc': 'images/gray-explanation.png',
  65. 'position': {
  66. x: 170,
  67. y: 321
  68. },
  69. 'width': 179,
  70. 'height': 100,
  71. 'type': 'fadeIn',
  72. 'duration': 500,
  73. 'id': 'fadeout-1',
  74. }
  75. ]),
  76. new Animation([
  77. {
  78. 'imagesrc': 'images/2-lines.png',
  79. 'position': {
  80. x: 385,
  81. y: 214
  82. },
  83. 'width': 244,
  84. 'height': 153,
  85. 'type': 'reveal',
  86. 'duration': 1000,
  87. }, {
  88. 'type': 'fadeOut',
  89. 'duration': 500,
  90. 'id': 'fadeout-1',
  91. }, {
  92. 'id': 'fadeout-2',
  93. 'type': 'fadeOut',
  94. 'duration': 500,
  95. 'delay': 250
  96. }], true // true = trigger the animation on click/tap
  97. )
  98. ]
  99. }

4.初始化插件并在您刚刚创建的容器中渲染动画。

  1. var myAnimation = new AnimationLoader('.example', options);
  2. myAnimation.init();

预览截图