021/100 Buttons.
Total time so far: 166h
A clean hover for a more serious/high-quality site, I would say.
I’m using GSAP here to animate the hover effect and SplitText for splitting the text into chars.
In the JavaScript, I have a few event listeners like pointerenter, pointerleave, focusin, and focusout.
For every state, I add separate functions where the animation happens.
We can see here that when we focus the button, the animation plays too. Just because the keyboard is being used doesn’t mean you shouldn’t show an animation. The animation just shouldn’t be visible when reduced motion is turned on.
In JS, we can use the focusin event listener for that. But as this also gets triggered when we click the button, we need to check if our element matches the CSS :focus-visible state, because that only works when using the keyboard.
If the check is true, we simply play the timeline with the hover animation.
On pointerleave, we overwrite our hover timeline to set every char back to its original state.
Crafted 100 Buttons with
@osmosupply
Available on Osmo