Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

#CSS feature faceoff: scroll triggered stuck nav (left) vs scroll driven animation nav (right) which do you prefer? try it (use Canary for the scroll-state() support)

12,330 görüntüleme • 1 yıl önce •via X (Twitter)

11 Yorum

Brandon McConnell profil fotoğrafı
Brandon McConnell1 yıl önce

Left, personally I still wish there was an easier way to do something like :stuck but I understand the reasoning behind not doing it In my own codebase, I actually support :stuck in tailwind via a custom `stuck` variant that uses JS IntersectionObserver API behind the scenes 😁

Adam Argyle profil fotoğrafı
Adam Argyle1 yıl önce

scroll-state(stuck: top) is pretty easy But yeah, not a one liner

CodeRabbit profil fotoğrafı
CodeRabbit1 yıl önce

AI-first pull request reviewer with context-aware feedback, line-by-line code suggestions, and real-time chat.

John Riordan profil fotoğrafı
John Riordan1 yıl önce

Like all of the other replies this example is designed for trigger. Driven animations I'd argue are for cases where every individual intermediate frame is equally "correct"/desired. I feel like a lot of the driven examples Ive seen are actually subtly trying to be triggered

Adam Argyle profil fotoğrafı
Adam Argyle1 yıl önce

Agree! but I also see the inverse, a page covered in triggered animations that woulda been better linked

Ryan Leichty profil fotoğrafı
Ryan Leichty1 yıl önce

The in-between state of the scroll driven animation isn’t very pleasant. I would only want background or no background with a transition between states

@css@tech.lgbt 🏳️‍🌈🏳️‍⚧️☭🌍🌹🕊️🌈🖖 profil fotoğrafı
@[email protected] 🏳️‍🌈🏳️‍⚧️☭🌍🌹🕊️🌈🖖1 yıl önce

Couldn't you set the right one to trigger after 1px though?

Adam Argyle profil fotoğrafı
Adam Argyle1 yıl önce

Yep, but sorta.. it could easily make it visible, but it can't simply trigger an interruptible opacity transition. to trigger a transition, you gotta do some tricky work, as it's unnatural to how scroll driven animations work

Daniel Vaughn profil fotoğrafı
Daniel Vaughn1 yıl önce

I prefer right, it feels more obvious what is going on. Left feels too abrupt

Martin Bean profil fotoğrafı
Martin Bean1 yıl önce

Neither. I absolutely hate web pages where things like headers change opacity, or shrink/grow as soon as I start scrolling.

Fabrizio Calderan profil fotoğrafı
Fabrizio Calderan1 yıl önce

I prefer the left one, but I would also change the colors of the login button when the header is white

Benzer Videolar

CSS Tip! 📜 You can use scroll-driven animations to progressively enhance collapsing a floating call to action 🤏 .cta { animation: shrink; animation-timeline: scroll(); animation-range: 0 100px; } @​keyframes shrink { to { width: 48px; } } That's the gist of it. Use the body scroll position with animation-timeline: scroll(). Define the animation-range as when you have scrolled 100px. There's a little more though 🤓 That would "scrub" the width animation. Ideally, you want to trigger that animation. You could animate a custom property with steps() timing and use that to define the width ✨ @​property --scrub { syntax: ' '; inherits: true; initial-value: 0; } body { animation: scrub both steps(1, end); animation-timeline: scroll(); animation-range: 0 100px; } Then transition the --scrub property on the CTA and use it for the width 🤙 .cta { transition: --scrub 0.2s; width: calc(48px + (120px * (1 - (var(--scrub) / 100)))); } Other animations are a matter of preference and timing. For example, you could then make the hand wave, scale down the size, and then slide a gradient across 😉 They have the same structure and technique as the original concept. Waving the hand? 👋 Run it twice, offset the transform-origin. .hand { animation: wave both linear 2; animation-timeline: scroll(); animation-range: 30vh 50vh; transform-origin: 65% 75%; } @​keyframes wave { 50% { rotate: 20deg; } } How's it progressively enhanced? Wrap everything in a @​supports query and a @​media query. If there isn't support, users still get a good experience. It's a floating action button that's circular and already collapsed 🤙 @​supports(animation-timeline: scroll()) { @​media(prefers-reduced-motion: no-preference) {...} } Definitely have a play with the code. Amazing what we're going to be able to do with CSS alone! 🔥 CodePen.IO link below! 👇

jhey ʕ•ᴥ•ʔ

177,781 görüntüleme • 2 yıl önce