Loading video...

Video Failed to Load

Go Home

CSS Scroll-Snapping + GSAP ScrollTrigger ๐Ÿ™€ What a lovely combo! I didn't know anything about #css scroll-snapping until studying a recent demo from Julio Rodriguez (linked below). I wanted to build my own simplified version from scratch to understand it better. Notice how the animated list of headers always...

29,409 views โ€ข 1 year ago โ€ขvia X (Twitter)

8 Comments

Carl ๐Ÿ’ฅ Creative Coding Club's profile picture
Carl ๐Ÿ’ฅ Creative Coding Club1 year ago

Here's my "basic" demo using @greensock's ScrollTrigger with CSS Scroll-Snapping

Carl ๐Ÿ’ฅ Creative Coding Club's profile picture
Carl ๐Ÿ’ฅ Creative Coding Club1 year ago

This is the inspiring, extra-fancy @jh3yy version And you can get in on his newsletter here:

Sam Sen | Web & Digital Design's profile picture
Sam Sen | Web & Digital Design1 year ago

@jhey Looks awesome!

crapthings's profile picture
crapthings1 year ago

@jhey cool

Dan Florian's profile picture
Dan Florian1 year ago

@jhey Works in safari. Thatโ€™s a shocker ๐Ÿ˜ฎ

Armando J. Perez-Carreno's profile picture
Armando J. Perez-Carreno1 year ago

@jhey Love the demo

Carl ๐Ÿ’ฅ Creative Coding Club's profile picture
Carl ๐Ÿ’ฅ Creative Coding Club1 year ago

@jhey Thanks!!!

Andy's profile picture
Andy1 year ago

@jhey Removing the scroll-snap CSS in html { } and li { } doesnโ€™t change the demo behavior at all. It looks like GSAP does all the lifting.

Related Videos

Future CSS Tip! ๐Ÿ You can create this Apple-style photo scroller by combining CSS scroll-driven animations and CSS scroll-snap ๐Ÿ˜ Peep those changing captions ๐Ÿ‘€ No JS! img { animation: highlight both linear; animation-timeline: view(inline); ๐Ÿ‘ˆ Horizontal animation-range: cover 0% cover 50%; ๐Ÿ‘ˆ Finish } @ keyframes highlight { 50% { translate: 0 0; scale: var(--starting-scale); ๐Ÿ‘ˆ props opacity: var(--starting-opacity); ๐Ÿ‘ˆ } 100% { translate: 0 0; scale: 1; opacity: 1; } } Without the animation support, you get a standard unordered list containing some s ๐Ÿค™ How do we swap the captions though? The "trick" is to use position: absolute on the figcaption and animate their opacity based on the ViewTimeline of their parent list item ๐Ÿ˜Ž figcaption { animation: show both linear; animation-timeline: --list-item; } @ keyframes show { 0%, 45%, 55%, 100% { opacity: 0; } 50% { opacity: 1; } } li { view-timeline-name: --list-item; view-timeline-axis: inline; ๐Ÿ‘ˆ important! } The parent of the scroll track uses position: relative so all the captions sit in the middle even though they are in the right place for the markup ๐Ÿ™Œ The last bit is the scroll-snap ๐Ÿค™ Not much to it at all. Wrap the list and make it scrollable. Then add scroll-snap-type .wrapper { scroll-snap-type: x mandatory; overflow-x: scroll; } Then make sure each list item has scroll-snap-align set on it li { scroll-snap-align: center; } That's it! Pretty cool demo to put together and see how to do this stuff with these APIs ๐Ÿค“ A lot of cool little tricks to pick up for writing your CSS! โญ๏ธ CodePen.IO link below! ๐Ÿ‘‡

jhey ส•โ€ขแดฅโ€ขส”

234,583 views โ€ข 2 years ago

CSS Trick! โšก๏ธ You can use scroll-driven animation with background-attachment to create a dynamic glowing card scroller without JS ๐Ÿ”ฅ section { animation:vibe; animation-timeline:--list; } @โ€‹keyframes vibe { to{--hue:320;}} .glow {background: hsl(var(--hue) 80% 50%);} Here's how! ๐Ÿค™ You can use the background-attachment trick used in other glow card demos ๐Ÿ˜Ž article { background-attachment: fixed; } The difference here is that you aren't going to update the fixed background position with your pointer this time. It can remain fixed. The magic part is that as you scroll, the background will leave the card that's leaving and enter the card that's entering โœจ For the extra background glow, you can use a fixed pseudo element on the list container itself ๐Ÿ’ช Once that's in place, you're only task is to change the color of the background as you scroll ๐Ÿค” Create a custom property declaration for the --hue @โ€‹property --base { inherits: true; syntax: ' '; initial-value: 0; } Then create an animation that updates this value @โ€‹keyframes accent { to { --hue: 320; }} The last piece is hooking it up to scroll and there is a little trick in here ๐Ÿ‘€ First, you need an inline scroll-timeline on the list ul { scroll-timeline: --list inline; } Then you can use timeline-scope to hoist that scroll-timeline up so a parent can use it. You then animate the custom property on this element and let the value cascade down to the places that need it ๐Ÿ”ฅ section { timeline-scope: --list; animation: accent both linear; animation-timeline: --list; } For example, the glow uses the --hue this way [data-glow] { background-image: radial-gradient( 150px 150px at 50% 50%, hsl(var(--hue) 100% 70% / 0.25), transparent ); } Lastly, scroll-snap is optional of course but plays nice with the scroll-driven animation demos โœจ The key for that is ul { scroll-snap-type: x mandatory; } li { scroll-snap-align: center; } That's it! Pretty fun trick to play with! ๐Ÿค“ Any questions, let me know! Should we add it to the video walkthrough list? CodePen.IO link below! ๐Ÿ‘‡

jhey ส•โ€ขแดฅโ€ขส”

116,625 views โ€ข 2 years ago