animal.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Animal.js Demo</title>
  7. <style>
  8. body { font-family: sans-serif; padding: 20px; max-width: 800px; margin: 0 auto; padding-bottom: 500px; }
  9. section { margin-bottom: 50px; border-bottom: 1px solid #eee; padding-bottom: 20px; }
  10. .box { width: 50px; height: 50px; background: #3498db; border-radius: 4px; margin-bottom: 10px; }
  11. .circle { width: 50px; height: 50px; background: #e74c3c; border-radius: 50%; }
  12. .btn { padding: 8px 16px; cursor: pointer; background: #333; color: white; border: none; border-radius: 4px; margin-top: 10px; }
  13. svg { border: 1px solid #ddd; }
  14. </style>
  15. </head>
  16. <body>
  17. <h1>Animal.js Demo</h1>
  18. <section>
  19. <h2>1. Basic Transform & Opacity (WAAPI)</h2>
  20. <div class="box box-1"></div>
  21. <button class="btn" onclick="runBasic()">Animate</button>
  22. <pre>animal.animate('.box-1', { x: 200, rotate: 180, opacity: 0.5, duration: 1000 })</pre>
  23. </section>
  24. <section>
  25. <h2>2. Spring Physics</h2>
  26. <div class="box box-2"></div>
  27. <button class="btn" onclick="runSpring()">Spring</button>
  28. <pre>animal.animate('.box-2', { x: 200, easing: { stiffness: 200, damping: 10 } })</pre>
  29. </section>
  30. <section>
  31. <h2>3. Timeline Sequence</h2>
  32. <div class="box box-3a" style="background: purple"></div>
  33. <div class="box box-3b" style="background: orange"></div>
  34. <button class="btn" onclick="runTimeline()">Run Timeline</button>
  35. </section>
  36. <section>
  37. <h2>4. SVG Draw</h2>
  38. <svg width="200" height="100" viewBox="0 0 200 100">
  39. <path class="path-1" fill="none" stroke="#2ecc71" stroke-width="5" d="M10,50 Q50,5 90,50 T190,50" />
  40. </svg>
  41. <br>
  42. <button class="btn" onclick="runSvg()">Draw SVG</button>
  43. </section>
  44. <section>
  45. <h2>5. In View Trigger</h2>
  46. <p>Scroll down to see the animation...</p>
  47. <div style="height: 110vh; background: linear-gradient(to bottom, #f9f9f9, #eee); display: flex; align-items: center; justify-content: center; color: #999;">
  48. Scroll Spacer (Keep scrolling)
  49. </div>
  50. <div class="box box-view" style="opacity: 0;"></div>
  51. </section>
  52. <script src="../animal.js"></script>
  53. <script>
  54. // 1. Basic
  55. function runBasic() {
  56. animal.animate('.box-1', {
  57. x: 200,
  58. rotate: 180,
  59. opacity: 0.5,
  60. duration: 1000,
  61. easing: 'ease-in-out'
  62. }).then(() => {
  63. console.log('Basic finished');
  64. // Chain back
  65. animal.animate('.box-1', { x: 0, rotate: 0, opacity: 1, duration: 500 });
  66. });
  67. }
  68. // 2. Spring
  69. function runSpring() {
  70. animal.animate('.box-2', {
  71. x: 200,
  72. easing: { stiffness: 150, damping: 8 }
  73. });
  74. }
  75. // 3. Timeline
  76. function runTimeline() {
  77. const tl = animal.timeline();
  78. tl.add('.box-3a', { x: 100, duration: 500 })
  79. .add('.box-3b', { x: 100, rotate: 90, duration: 800 }, "-=200") // Overlap
  80. .add('.box-3a', { x: 0, duration: 500 })
  81. .add('.box-3b', { x: 0, rotate: 0, duration: 500 });
  82. }
  83. // 4. SVG
  84. function runSvg() {
  85. animal.svgDraw('.path-1', { duration: 1500, easing: 'ease-in-out' });
  86. }
  87. // 5. In View
  88. // Use explicit from-to for spring to ensure correct start position
  89. animal.inViewAnimate('.box-view', {
  90. x: [-100, 0],
  91. opacity: [0, 1],
  92. duration: 1000,
  93. easing: { stiffness: 50, damping: 15 } // slow spring
  94. }, { threshold: 0.5 });
  95. </script>
  96. </body>
  97. </html>