Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

soon: CSS only sticky scroll hide/reveal 🧑‍🍳 .atc { position: fixed; bottom: 0; transition: translate 0.26s cubic-bezier(.55,0,.67,1.25); /* hide on scroll down */ @​container scroll-state(scrolled: bottom) { translate: 0 100%; transition-delay: 0.5s; } }

66,423 Aufrufe • vor 1 Jahr •via X (Twitter)

13 Kommentare

Profilbild von Victor Rivas
Victor Rivasvor 1 Jahr

Top top!!

Profilbild von jhey ʕ•ᴥ•ʔ
jhey ʕ•ᴥ•ʔvor 1 Jahr

@readytorelease it’s at the bottom though 🥁😅

Profilbild von Jan Nicklas
Jan Nicklasvor 1 Jahr

wow - is it also possible to build a scrolled bottom once?

Profilbild von jhey ʕ•ᴥ•ʔ
jhey ʕ•ᴥ•ʔvor 1 Jahr

like a tuck away and forget after scrolling from the top but towards the bottom? you could do a scroll animation that triggers a translation at a certain point that then wouldn’t trigger again until scrolling back up

Profilbild von Michaël
Michaëlvor 6 Monaten

One current limitation is the inability to specify an offset. For instance, in our case we would like to hide a header after scrolling for a given amount. Having a way to define scroll-state(scrolled: bottom by 100px) for instance would be nice! Is this something being planned?

Profilbild von jhey ʕ•ᴥ•ʔ
jhey ʕ•ᴥ•ʔvor 6 Monaten

yeah, agreed 💯 it kinda feels like you'd want something a bit like scroll-margin/padding-top to have an effect on the scroll-state trigger 🤔

Profilbild von Michaël
Michaëlvor 6 Monaten

Exactly. Using scroll-margin/padding was actually my first intuition, but this did not work!

Profilbild von ᴋᴏᴠᴀʀ
ᴋᴏᴠᴀʀvor 1 Jahr

Is it fully supported finally?

Profilbild von Fabrizio Calderan
Fabrizio Calderanvor 1 Jahr

You may achieve a similar behaviour using custom properties and style queries

Profilbild von jhey ʕ•ᴥ•ʔ
jhey ʕ•ᴥ•ʔvor 1 Jahr

find this one unreliable unfortunately, it’s easy to get into a state where it doesn’t appear when you want it to

Profilbild von gumbo701
gumbo701vor 1 Jahr

Css is beautiful

Profilbild von Human
Humanvor 10 Monaten

Is it possible to have a sticky block hide/reveal as you scroll, rather than through a transition animation?

Profilbild von gokhan
gokhanvor 1 Jahr

Cool. I think it's somewhat possible with scroll/view states already.

Ähnliche Videos

CSS Tip! 🍬 You can create a CSS-only sticky CTA using position: sticky or scroll-driven animations 🤙 .cta { position: sticky; margin-top: 110vh; bottom: 2rem; /* 👈 Stick! */ } This is one way 👀 This first way relies on you setting a layout on the body and putting the CTA in a zero-space part of the layout body { display: grid; grid-template-columns: auto 0; } The children of the body are an element with your content and then the CTA. You could also use display:flex too. .content { flex: 1 0 100%; } .cta { place-self: end; } As you scroll the body, the CTA comes into view and sticks in position 🙌 That's one way. If you want to take it further and do something like flip between showing or not, maybe scale it up, or add some special easing, etc. an animation is another way 📜 First, change the styles for your CTA. Note the translate property that's powered by a custom property .cta { position: fixed; bottom: 2rem; right: 2rem; translate: 0 calc(20vh - (var(--show) * 20vh)); transition: translate 0.875s var(--elastic); } Next you need a custom property that you're going to animate @​property --show { inherits: true; initial-value: 0; syntax: ' '; } Lastly, you animate this value on the body. As the property value changes, the value will trickle down to the CTA @​supports (animation-timeline: scroll()) { body { animation: show-cta both steps(1); animation-timeline: scroll(root); animation-range: 0 10vh; } @​keyframes show-cta { to { --show: 1; } } } Using @​supports you can use this as a progressive enhancement. If scroll-driven animations are supported, use them. Otherwise fallback to using position: sticky 🤙 That's it! As always, any questions or requests, hit me up! 🙏 CodePen.IO link below! 👇

jhey ʕ•ᴥ•ʔ

133,020 Aufrufe • vor 2 Jahren