animal.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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>$('.box-1').animate({ 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>$('.box-2').animate({ 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. // Alias
  90. const $ = animal;
  91. // 1. Basic
  92. function runBasic() {
  93. $('.box-1').animate({
  94. x: 200,
  95. rotate: 180,
  96. opacity: 0.5,
  97. duration: 1000,
  98. easing: 'ease-in-out'
  99. }).then(() => {
  100. console.log('Basic finished');
  101. // Chain back
  102. $('.box-1').animate({ x: 0, rotate: 0, opacity: 1, duration: 500 });
  103. });
  104. }
  105. // 2. Spring
  106. function runSpring() {
  107. $('.box-2').animate({
  108. x: 200,
  109. easing: { stiffness: 150, damping: 8 }
  110. });
  111. }
  112. // 3. Timeline
  113. function runTimeline() {
  114. const tl = $.timeline();
  115. tl.add('.box-3a', { x: 100, duration: 500 })
  116. .add('.box-3b', { x: 100, rotate: 90, duration: 800 }, "-=200") // Overlap
  117. .add('.box-3a', { x: 0, duration: 500 })
  118. .add('.box-3b', { x: 0, rotate: 0, duration: 500 })
  119. .play();
  120. }
  121. // 4. SVG
  122. function runSvg() {
  123. $('.path-1').draw({ duration: 1500, easing: 'ease-in-out' });
  124. }
  125. // 5. In View (Trigger)
  126. // Staggered logic: observe each
  127. const cards = document.querySelectorAll('.card');
  128. cards.forEach((card, i) => {
  129. // Alternate left/right entrance
  130. const xStart = i % 2 === 0 ? -100 : 100;
  131. // inViewAnimate() returns cleanup; call it if you use once:false or if you need to teardown manually.
  132. $(card).inViewAnimate({
  133. x: [xStart, 0],
  134. opacity: [0, 1],
  135. scale: [0.8, 1],
  136. duration: 1000,
  137. easing: { stiffness: 100, damping: 15 },
  138. springFrames: 60
  139. }, { threshold: 0.2 });
  140. });
  141. // 6. Scroll Linked
  142. // 1. Progress Bar (Page Scroll)
  143. const progressAnim = $('.progress-bar').animate({
  144. width: ['0%', '100%'],
  145. duration: 1000, // Duration doesn't matter much for scroll linked, just maps 0-1
  146. autoplay: false
  147. });
  148. $.scroll(progressAnim); // Default: window scroll
  149. // 2. Box Rotation (Element Scroll Visibility)
  150. const boxAnim = $('.scroll-box').animate({
  151. rotate: 360,
  152. x: 200,
  153. backgroundColor: '#e74c3c',
  154. duration: 1000,
  155. autoplay: false
  156. });
  157. // Scroll linked to the entire page scroll (simplest demo)
  158. // Or we can link it to when the section is in view if we implemented element-target logic in animal.js
  159. // animal.js current `scroll` implementation supports `target` for element visibility progress!
  160. // Let's link it to the page scroll for clarity
  161. $.scroll(boxAnim);
  162. </script>
  163. </body>
  164. </html>