|
| 1 | +/* ========================================================================== |
| 2 | + #HAPPY-HARRY |
| 3 | + ========================================================================== */ |
| 4 | + |
| 5 | +/** |
| 6 | + * On devices that support it, make me do a happy dance when you hover the |
| 7 | + * Call to Action link in the sidebar. |
| 8 | + */ |
| 9 | + |
| 10 | +@media (pointer: fine) { |
| 11 | + |
| 12 | + @keyframes happy-harry { |
| 13 | + |
| 14 | + 0% { |
| 15 | + transform: translateY(0) translateX(0) rotate(0deg) scale(1); |
| 16 | + box-shadow: 0 4px 12px rgba(0,0,0,0.25); |
| 17 | + animation-timing-function: cubic-bezier(.36,0,.08,1); |
| 18 | + } |
| 19 | + |
| 20 | + /* Hop 1 */ |
| 21 | + 12.5% { |
| 22 | + transform: translateY(-6px) translateX(-2px) rotate(-3deg) scale(1.03); |
| 23 | + box-shadow: 0 8px 20px rgba(0,0,0,0.18); /* lighter, further away */ |
| 24 | + animation-timing-function: cubic-bezier(.22,1,.36,1); |
| 25 | + } |
| 26 | + 25% { |
| 27 | + transform: translateY(0) translateX(0) rotate(0deg) scale(1); |
| 28 | + box-shadow: 0 4px 12px rgba(0,0,0,0.28); /* fuller on landing */ |
| 29 | + animation-timing-function: cubic-bezier(.36,0,.08,1); |
| 30 | + } |
| 31 | + |
| 32 | + /* Hop 2 */ |
| 33 | + 37.5% { |
| 34 | + transform: translateY(-8px) translateX(2px) rotate(3deg) scale(1.04); |
| 35 | + box-shadow: 0 10px 22px rgba(0,0,0,0.16); |
| 36 | + animation-timing-function: cubic-bezier(.22,1,.36,1); |
| 37 | + } |
| 38 | + 50% { |
| 39 | + transform: translateY(0) translateX(0) rotate(0deg) scale(1); |
| 40 | + box-shadow: 0 5px 14px rgba(0,0,0,0.3); |
| 41 | + animation-timing-function: cubic-bezier(.36,0,.08,1); |
| 42 | + } |
| 43 | + |
| 44 | + /* Hop 3 */ |
| 45 | + 62.5% { |
| 46 | + transform: translateY(-5px) translateX(-1px) rotate(-2deg) scale(1.02); |
| 47 | + box-shadow: 0 7px 18px rgba(0,0,0,0.2); |
| 48 | + animation-timing-function: cubic-bezier(.22,1,.36,1); |
| 49 | + } |
| 50 | + 75% { |
| 51 | + transform: translateY(0) translateX(0) rotate(0deg) scale(1); |
| 52 | + box-shadow: 0 4px 12px rgba(0,0,0,0.28); |
| 53 | + animation-timing-function: cubic-bezier(.36,0,.08,1); |
| 54 | + } |
| 55 | + |
| 56 | + /* A little skip */ |
| 57 | + 87.5% { |
| 58 | + transform: translateY(-3px) translateX(1px) rotate(1.5deg) scale(1.01); |
| 59 | + box-shadow: 0 6px 16px rgba(0,0,0,0.22); |
| 60 | + animation-timing-function: cubic-bezier(.22,1,.36,1); |
| 61 | + } |
| 62 | + |
| 63 | + /* 🕺 */ |
| 64 | + 100% { |
| 65 | + transform: translateY(0) translateX(0) rotate(0deg) scale(1); |
| 66 | + box-shadow: 0 4px 12px rgba(0,0,0,0.25); |
| 67 | + } |
| 68 | + |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * The target image. |
| 73 | + */ |
| 74 | + .c-happy-harry { |
| 75 | + will-change: transform; |
| 76 | + |
| 77 | + /** |
| 78 | + * `:has()` is a super power! If the document has a `:hover`ed trigger, |
| 79 | + * start animating the target image. |
| 80 | + */ |
| 81 | + html:has(.c-happy-harry-trigger:hover, |
| 82 | + .c-happy-harry-trigger:active, |
| 83 | + .c-happy-harry-trigger:focus) & { |
| 84 | + animation: happy-harry .85s ease-in-out infinite; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | +} |
| 89 | + |
| 90 | +@media (prefers-reduced-motion: reduce){ |
| 91 | + |
| 92 | + html:has(.c-happy-harry-trigger:hover, |
| 93 | + .c-happy-harry-trigger:active, |
| 94 | + .c-happy-harry-trigger:focus) .c-happy-harry { |
| 95 | + animation:none; |
| 96 | + } |
| 97 | + |
| 98 | +} |
0 commit comments