animal.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. /* Styles for Section 5 */
  15. .scroll-section {
  16. padding: 50px 0;
  17. display: flex;
  18. flex-direction: column;
  19. gap: 400px; /* Large gaps to force scrolling */
  20. align-items: center;
  21. }
  22. .card {
  23. width: 150px; height: 200px;
  24. background: linear-gradient(135deg, #6e8efb, #a777e3);
  25. border-radius: 8px;
  26. box-shadow: 0 10px 20px rgba(0,0,0,0.1);
  27. display: flex; align-items: center; justify-content: center;
  28. color: white; font-weight: bold; font-size: 32px;
  29. opacity: 0;
  30. }
  31. /* Styles for Section 6 (Scroll Linked) */
  32. .progress-bar {
  33. position: fixed; top: 0; left: 0; height: 5px; background: red; width: 0%; z-index: 100;
  34. }
  35. .scroll-box {
  36. width: 100px; height: 100px; background: #2c3e50; margin: 50px auto;
  37. color: white; display: flex; align-items: center; justify-content: center;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <div class="progress-bar"></div>
  43. <h1>Animal.js Demo</h1>
  44. <section>
  45. <h2>1. Basic Transform & Opacity (WAAPI)</h2>
  46. <div class="box box-1"></div>
  47. <button class="btn" onclick="runBasic()">Animate</button>
  48. <pre>animal.animate('.box-1', { x: 200, rotate: 180, opacity: 0.5, duration: 1000 })</pre>
  49. </section>
  50. <section>
  51. <h2>2. Spring Physics</h2>
  52. <div class="box box-2"></div>
  53. <button class="btn" onclick="runSpring()">Spring</button>
  54. <pre>animal.animate('.box-2', { x: 200, easing: { stiffness: 200, damping: 10 } })</pre>
  55. </section>
  56. <section>
  57. <h2>3. Timeline Sequence</h2>
  58. <div class="box box-3a" style="background: purple"></div>
  59. <div class="box box-3b" style="background: orange"></div>
  60. <button class="btn" onclick="runTimeline()">Run Timeline</button>
  61. </section>
  62. <section>
  63. <h2>4. SVG Draw</h2>
  64. <svg width="200" height="100" viewBox="0 0 200 100">
  65. <path class="path-1" fill="none" stroke="#2ecc71" stroke-width="5" d="M10,50 Q50,5 90,50 T190,50" />
  66. </svg>
  67. <br>
  68. <button class="btn" onclick="runSvg()">Draw SVG</button>
  69. </section>
  70. <section>
  71. <h2>5. In View Trigger (Staggered Scroll)</h2>
  72. <p>Scroll down slowly. Cards will appear as they enter the view.</p>
  73. <div class="scroll-section">
  74. <div class="card card-1">1</div>
  75. <div class="card card-2">2</div>
  76. <div class="card card-3">3</div>
  77. </div>
  78. <p style="text-align: center; color: #aaa;">(End of trigger section)</p>
  79. </section>
  80. <section>
  81. <h2>6. Scroll Linked Animation</h2>
  82. <p>This box rotates and moves based on scroll position of the page.</p>
  83. <div class="scroll-box">Rotate</div>
  84. <div style="height: 50vh;"></div>
  85. </section>
  86. <script src="../animal.js"></script>
  87. <script>
  88. // 1. Basic
  89. function runBasic() {
  90. animal.animate('.box-1', {
  91. x: 200,
  92. rotate: 180,
  93. opacity: 0.5,
  94. duration: 1000,
  95. easing: 'ease-in-out'
  96. }).then(() => {
  97. console.log('Basic finished');
  98. // Chain back
  99. animal.animate('.box-1', { x: 0, rotate: 0, opacity: 1, duration: 500 });
  100. });
  101. }
  102. // 2. Spring
  103. function runSpring() {
  104. animal.animate('.box-2', {
  105. x: 200,
  106. easing: { stiffness: 150, damping: 8 }
  107. });
  108. }
  109. // 3. Timeline
  110. function runTimeline() {
  111. const tl = animal.timeline();
  112. tl.add('.box-3a', { x: 100, duration: 500 })
  113. .add('.box-3b', { x: 100, rotate: 90, duration: 800 }, "-=200") // Overlap
  114. .add('.box-3a', { x: 0, duration: 500 })
  115. .add('.box-3b', { x: 0, rotate: 0, duration: 500 });
  116. }
  117. // 4. SVG
  118. function runSvg() {
  119. animal.svgDraw('.path-1', { duration: 1500, easing: 'ease-in-out' });
  120. }
  121. // 5. In View (Trigger)
  122. // Staggered logic: observe each
  123. const cards = document.querySelectorAll('.card');
  124. cards.forEach((card, i) => {
  125. // Alternate left/right entrance
  126. const xStart = i % 2 === 0 ? -100 : 100;
  127. animal.inViewAnimate(card, {
  128. x: [xStart, 0],
  129. opacity: [0, 1],
  130. scale: [0.8, 1],
  131. duration: 1000,
  132. easing: { stiffness: 100, damping: 15 }
  133. }, { threshold: 0.2 });
  134. });
  135. // 6. Scroll Linked
  136. // 1. Progress Bar (Page Scroll)
  137. const progressAnim = animal.animate('.progress-bar', {
  138. width: ['0%', '100%'],
  139. duration: 1000, // Duration doesn't matter much for scroll linked, just maps 0-1
  140. autoplay: false
  141. });
  142. animal.scroll(progressAnim); // Default: window scroll
  143. // 2. Box Rotation (Element Scroll Visibility)
  144. const boxAnim = animal.animate('.scroll-box', {
  145. rotate: 360,
  146. x: 200,
  147. backgroundColor: '#e74c3c',
  148. duration: 1000,
  149. autoplay: false
  150. });
  151. // Scroll linked to the entire page scroll (simplest demo)
  152. // Or we can link it to when the section is in view if we implemented element-target logic in animal.js
  153. // animal.js current `scroll` implementation supports `target` for element visibility progress!
  154. // Let's link it to the page scroll for clarity
  155. animal.scroll(boxAnim);
  156. </script>
  157. </body>
  158. </html>