|
36 | 36 | </div> |
37 | 37 | <div class="nav-section"> |
38 | 38 | <ul role="menubar"> |
39 | | - <li role="none"><a href="#examples" class="secondary" role="menuitem">Examples</a></li> |
40 | 39 | <li role="none"><a href="#features" class="secondary" role="menuitem">Features</a></li> |
41 | 40 | <li role="none"><a href="./docs/" class="secondary" role="menuitem">Docs</a></li> |
42 | 41 | <li> |
@@ -509,74 +508,55 @@ <h3>Parameters</h3> |
509 | 508 | <footer> |
510 | 509 | <div class="container"> |
511 | 510 | <ul> |
512 | | - <li><a href="#examples" class="contrast">Examples</a></li> |
513 | 511 | <li><a href="#features" class="contrast">Features</a></li> |
514 | 512 | <li><a href="./docs/" class="contrast">Docs</a></li> |
515 | 513 | <li><a href="https://github.com/cppalliance/mrdocs" class="contrast">GitHub</a></li> |
516 | 514 | </ul> |
517 | 515 | </div> |
518 | 516 | </footer> |
519 | 517 | <script> |
| 518 | + // Initialize positions to match CSS exactly |
| 519 | + document.addEventListener('DOMContentLoaded', function() { |
| 520 | + const root = document.documentElement; |
| 521 | + |
| 522 | + // Set initial positions to exactly match CSS defaults |
| 523 | + root.style.setProperty('--x1', '20%'); |
| 524 | + root.style.setProperty('--y1', '20%'); |
| 525 | + root.style.setProperty('--x2', '75%'); |
| 526 | + root.style.setProperty('--y2', '25%'); |
| 527 | + root.style.setProperty('--x3', '50%'); |
| 528 | + root.style.setProperty('--y3', '50%'); |
| 529 | + }); |
| 530 | + |
520 | 531 | window.addEventListener("scroll", () => { |
521 | 532 | const t = window.scrollY / (document.body.scrollHeight - window.innerHeight); |
522 | 533 | const root = document.documentElement; |
523 | 534 |
|
524 | | - const ease = (x) => 0.5 - Math.cos(x * Math.PI) / 2; // smooth easing |
525 | | - |
526 | | - // Update positions and radii |
| 535 | + // Original animation formula but adjusted to start from CSS positions |
527 | 536 | for (let i = 1; i <= 3; i++) { |
528 | 537 | const angle = t * Math.PI * 2 + i; |
529 | | - const radius = 15 + 5 * (i % 2); // motion amplitude |
530 | | - const blobSize = 25 + 10 * Math.sin(t * Math.PI * 2 + i); // animated radius % |
531 | | - const cx = 50 + radius * Math.cos(angle + i); |
532 | | - const cy = 50 + radius * Math.sin(angle + i * 0.5); |
| 538 | + const radius = 15 + 5 * (i % 2); // original motion amplitude |
| 539 | + |
| 540 | + // Calculate what the original formula produces at t=0 |
| 541 | + const angle0 = 0 * Math.PI * 2 + i; // t=0 |
| 542 | + const baseX = 50 + radius * Math.cos(angle0 + i); |
| 543 | + const baseY = 50 + radius * Math.sin(angle0 + i * 0.5); |
| 544 | + |
| 545 | + // Calculate current animation position |
| 546 | + const animX = 50 + radius * Math.cos(angle + i); |
| 547 | + const animY = 50 + radius * Math.sin(angle + i * 0.5); |
| 548 | + |
| 549 | + // Apply offset to match CSS starting positions |
| 550 | + const offsetX = (i === 1) ? 20 - baseX : (i === 2) ? 75 - baseX : 50 - baseX; |
| 551 | + const offsetY = (i === 1) ? 20 - baseY : (i === 2) ? 25 - baseY : 50 - baseY; |
| 552 | + |
| 553 | + const cx = animX + offsetX; |
| 554 | + const cy = animY + offsetY; |
533 | 555 |
|
534 | 556 | root.style.setProperty(`--x${i}`, `${cx}%`); |
535 | 557 | root.style.setProperty(`--y${i}`, `${cy}%`); |
536 | | - root.style.setProperty(`--r${i}`, `${blobSize}%`); |
537 | 558 | } |
538 | 559 | }); |
539 | | - |
540 | | - // Navigation scroll behavior |
541 | | - document.addEventListener('DOMContentLoaded', function() { |
542 | | - const nav = document.querySelector('.nav'); |
543 | | - const body = document.body; |
544 | | - const scrollThreshold = 300; |
545 | | - |
546 | | - function handleScroll() { |
547 | | - const currentScrollY = window.scrollY; |
548 | | - |
549 | | - if (currentScrollY > scrollThreshold) { |
550 | | - nav.classList.add('nav-visible'); |
551 | | - body.classList.add('nav-visible'); |
552 | | - } else { |
553 | | - nav.classList.remove('nav-visible'); |
554 | | - body.classList.remove('nav-visible'); |
555 | | - } |
556 | | - } |
557 | | - |
558 | | - // Throttle scroll events for performance |
559 | | - let ticking = false; |
560 | | - function updateNav() { |
561 | | - handleScroll(); |
562 | | - ticking = false; |
563 | | - } |
564 | | - |
565 | | - window.addEventListener('scroll', function() { |
566 | | - if (!ticking) { |
567 | | - requestAnimationFrame(updateNav); |
568 | | - ticking = true; |
569 | | - } |
570 | | - }); |
571 | | - |
572 | | - // Handle keyboard accessibility |
573 | | - document.addEventListener('keydown', function(e) { |
574 | | - if (e.key === 'Escape') { |
575 | | - nav.classList.remove('nav-visible'); |
576 | | - body.classList.remove('nav-visible'); |
577 | | - } |
578 | | - }); |
579 | | - }); |
580 | 560 | </script> |
581 | 561 | </body> |
582 | 562 |
|
|
0 commit comments