Loading video...

Video Failed to Load

Go Home

Future CSS Tip! ๐Ÿ”ฎ You can combine scroll-driven animation and anchor positioning to create a CSS only nav indicator ๐Ÿคฏ .el { animation: move; animation-timeline: --blog; } keyframes move {to { left: anchor(--blog left); }} Adapts to long text! ๐Ÿ˜Ž CodePen.IO link below! ๐Ÿ‘‡

129,244 views โ€ข 2 years ago โ€ขvia X (Twitter)

9 Comments

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ2 years ago

Here's that @CodePen link! ๐Ÿš€ You'll need to be in Chrome Canary to see this one in action as it requires Chromium 116+ ๐Ÿ‘€ But, it's pretty exciting to think what's possible with these APIs ๐Ÿ”ฅ

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ2 years ago

And here's a shot of it updating to really long text in real-time ๐Ÿ˜Ž CSS anchor-positioning will grab the left and right of whatever element is asked for and it will return a live value ๐Ÿ”ฅ [contenteditable] to the rescue! ๐Ÿ˜…

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ2 years ago

The gist of this demo is that 1. Anchor an indicator to the "Home" link 2. As we scroll animate a custom property change 3. That updates the CSS anchor position with the indicator moving to the relevant anchor ๐Ÿค“ There's a little more to it than that. But, it's Friday! ๐Ÿ˜…

rich spirit's profile picture
rich spirit2 years ago

@CodePen you..are goated

Khaled's profile picture
Khaled2 years ago

@CodePen Pretty neat! That would solve a problem I'm currently facing, gonna try to implement this with Tailwind

Antonio Craveiro Jr's profile picture
Antonio Craveiro Jr2 years ago

@CodePen @SaveToNotion

Rob Winter โ„๏ธ ๐Ÿ‡บ๐Ÿ‡ฆ's profile picture
Rob Winter โ„๏ธ ๐Ÿ‡บ๐Ÿ‡ฆ2 years ago

@CodePen I can see this being very popular. Single page sites with clear sections will have usable navigation. ๐ŸคŒ๐Ÿป

Jordan Fortin's profile picture
Jordan Fortin2 years ago

@CodePen You can do that with basic HTML & CSS, just saying why do all the extra work

jhey โ–ฒ๐Ÿป๐ŸŽˆ's profile picture
jhey โ–ฒ๐Ÿป๐ŸŽˆ2 years ago

@CodePen This is just HTML & CSS ๐Ÿค” Show me how you create the nav indicator without using the new APIs

Related Videos