animate.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Animate</title>
  5. <script src="../dist/kity.js"></script>
  6. <script>
  7. window.onload = function () {
  8. var paper = new kity.Paper(document.body);
  9. paper.setViewBox(0, 0, 1200, 600);
  10. // 定义反弹动画器
  11. var bounce = new kity.Animator(0, 400, function(target, y, timeline) {
  12. target.translate(0, timeline.getDelta());
  13. });
  14. // 定义颜色动画器
  15. var colorChanger = new kity.Animator({
  16. beginValue: function(target) {
  17. return target.color;
  18. },
  19. finishValue: function(target) {
  20. return target.color.inc('h', 90)
  21. },
  22. setter: function(target, color) {
  23. target.fill(color);
  24. }
  25. });
  26. // 定义形变函数
  27. function atternuate(e) {
  28. e.target.scale(1 + Math.sign((Math.random() - 0.5)) * Math.random());
  29. }
  30. for(var i = 0; i < 200; i++) {
  31. var color = kity.Color.createHSL(i * 30 % 360, 80, 50);
  32. var copy = new kity.Rect(5, 20, 0, 10).translate( i * 5, 0 );
  33. copy.color = color;
  34. copy.fill(color);
  35. paper.addShape(copy);
  36. bounce.start(copy, 500, 'easeInQuad', Math.random() * 5000).repeat(true, true).on('rollback', atternuate);
  37. colorChanger.start(copy, 500, 'linear').repeat(true, true);
  38. copy.fxTranslate(0, 300, '1s', 'easeInQuad', Math.random() * 5000);
  39. copy.fxTranslate(100, -100, '0.1s', 'easeOutQuad');
  40. copy.fxRotate(1080, '2s', 'linear', 500);
  41. copy.fxScale(.5, .5, '0.8s', 'easeInElastic');
  42. copy.fxTranslate(100, -200, '0.8s', 'easeOutElastic');
  43. copy.fadeOut(300).fadeIn(1000).fadeTo(.5, 100);
  44. }
  45. };
  46. </script>
  47. </head>
  48. <body>
  49. </body>
  50. </html>