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 ส•โ€ขแดฅโ€ขส”

232,131 views โ€ข 2 years ago