项目作者: oOthkOo

项目描述 :
Frame Animation Manager
高级语言: HTML
项目地址: git://github.com/oOthkOo/clockz.js.git
创建时间: 2013-05-08T13:21:14Z
项目社区:https://github.com/oOthkOo/clockz.js

开源协议:MIT License

下载


Clockz.js (demo)

Screenshot

Clockz is a Super-smooth Frame Animation manager to help you manage multiples animations in same time.

Installation

Just include this script after jQuery. Requires jQuery 1.4+.

  1. <script src='js/jquery.js'></script>
  2. <script src='js/clockz.js'></script>

Animation

This is how you can define a complex animation.

  1. var myAnim = {
  2. name: 'phone2', // Animation name
  3. loop: true, // looping ? (default: false)
  4. loopStart: 0, // loop start frame index (default: 0)
  5. loopEnd: 3, // loop end frame index
  6. frames: [
  7. {
  8. duration: 2000 // Frame duration, used without properties to pause
  9. },
  10. {
  11. type: 'jquery', // Frame type, used for hook (default: jquery)
  12. properties: { // Frame properties
  13. left: 410
  14. },
  15. duration: 800, // Frame properties
  16. easing: 'swing' // Frame easing
  17. }
  18. ]
  19. };

Hook

With a hook function, you can manage multiples animation frameworks like jQuery, Transit, Greensock and much mores.

  1. clockz.playHook = function(node, frame, callback) {
  2. var duration = frame.duration || 400;
  3. var properties = frame.properties || null;
  4. if (properties) {
  5. var jnode = $(node); // node selector (ex: '.class','#id' etc..)
  6. if (!jnode) {
  7. this.error( 'playHook(): node is invalid.' );
  8. return;
  9. }
  10. var type = frame.type || 'jquery';
  11. var easing = frame.easing || 'swing';
  12. switch (type) {
  13. // handle jQuery frames
  14. case 'jquery':
  15. $(node).animate(properties, duration, easing, callback);
  16. break;
  17. // handle Transit frames
  18. case 'transit':
  19. $(node).transition($.extend({
  20. duration: duration,
  21. easing: easing,
  22. complete: callback
  23. }, properties));
  24. break;
  25. // handle Greensock frames
  26. case 'greensock':
  27. // ...
  28. break;
  29. }
  30. }
  31. else {
  32. setTimeout(callback, duration); // to pause animation when no frame properties found
  33. }
  34. };

Usage

This is a complete example to see Clockz in action ;-)

  1. $(function () {
  2. // create a new clockz manager
  3. var clockz = new Clockz();
  4. console.log( 'jquery: ' + $().jquery );
  5. console.log( 'clockz: ' + clockz.version );
  6. var anim1 = {
  7. name: 'anim1',
  8. loop: true,
  9. loopStart: 1,
  10. loopEnd: 2,
  11. loopRepeat: 5,
  12. frames: [
  13. {
  14. properties: { left: 300, opacity: 0.2, width: 200, height: 200 },
  15. duration: 1000,
  16. easing: 'swing'
  17. },
  18. {
  19. properties: { top: 300, opacity: 1 },
  20. duration: 1000,
  21. easing: 'swing'
  22. },
  23. {
  24. properties: { top: 10, left: 10, width: 150, height: 150 },
  25. duration: 1000,
  26. easing: 'swing'
  27. }
  28. ]
  29. };
  30. var anim2 = {
  31. name: 'anim2',
  32. loop: true,
  33. frames: [
  34. {
  35. properties: { top: 300 },
  36. duration: 2000,
  37. easing: 'swing'
  38. },
  39. {
  40. type: 'transit',
  41. properties: { rotate: '+=30', },
  42. duration: 400,
  43. easing: 'fast'
  44. },
  45. {
  46. properties: { left: 500, opacity: 0.2 },
  47. duration: 1000,
  48. easing: 'swing'
  49. },
  50. {
  51. type: 'transit',
  52. properties: { rotate: '+=30' },
  53. duration: 400,
  54. easing: 'fast'
  55. },
  56. {
  57. properties: { top: 10, left: 10, opacity: 1 },
  58. duration: 1000,
  59. easing: 'swing'
  60. }
  61. ]
  62. };
  63. // redefine a clockz hook function to manage
  64. // jQuery, Transit and Greensock animation frameworks
  65. clockz.playHook = function(node, frame, callback) {
  66. var duration = frame.duration || 400;
  67. var properties = frame.properties || null;
  68. if (properties) {
  69. var jnode = $(node); // node selector (ex: '.class','#id' etc..)
  70. if (!jnode) {
  71. this.error( 'playHook(): node is invalid.' );
  72. return;
  73. }
  74. var type = frame.type || 'jquery';
  75. var easing = frame.easing || 'swing';
  76. switch (type) {
  77. // handle jQuery frames
  78. case 'jquery':
  79. $(node).animate(properties, duration, easing, callback);
  80. break;
  81. // handle Transit frames
  82. case 'transit':
  83. $(node).transition($.extend({
  84. duration: duration,
  85. easing: easing,
  86. complete: callback
  87. }, properties));
  88. break;
  89. // handle Greensock frames
  90. case 'greensock':
  91. // ...
  92. break;
  93. }
  94. }
  95. else {
  96. setTimeout(callback, duration); // to pause animation when no frame properties found
  97. }
  98. };
  99. clockz.create('#block1', anim1); // link an anim1 with #block1
  100. clockz.create('#block2', anim2); // link an anim2 with #block2
  101. clockz.playAll(); // play all animations
  102. });

Donations

:heart: Donations are always welcome :heart:.

Coins Symbols Addresses
Bitcoin BTC 3B52fbzNFQTaKZxWf5GrCUsASD2UP8na4A
Ethereum ETH 0x1C389f1f85Cdb3C2996b83fAc87E496A80698B7C
Solana SOL F14pWhGjGLcCF8RMk4JhbK2kD49iBBwa9KFygRJo54Fm