animal.html 6.5 KB

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