jhey Κ•β€’α΄₯β€’Κ” Profile picture
Aug 24, 2022 β€’ 10 tweets β€’ 5 min read β€’ Read on X
CSS Tip! πŸš€

You can select the previous siblings of an element with :has() to create cool hover effects like this OS dockπŸ”₯ No JS 😎

:root{--lerp-1:0.525;}
a:has(+a:hover){
--lerp:var(--lerp-1);
translate: 0 calc(var(--lerp) * -75%);
}

Demo link and explanation below! πŸ‘‡
First, here's that @CodePen link! πŸš€

You'll need to be in Safari, Chrome BETA, or you can use Chrome/Firefox with flags enabled ⛳️

Try not only :hovering the items, but also tabbing through them too ✨

codepen.io/jh3y/pen/mdxgg…
How do we get the nice easing curve on :hover? 🧐

The trick is creating a set of custom properties based on an easing curve πŸ€“

For, example the easing curve custom properties for this demo are πŸ‘‡ :root { 	--lerp-0: 1;   --l...
Then to apply this, we need rules that update the --lerp custom property on :hover or :focus for each item or block ✨

This code below caters for selecting 5 blocks with a combination of sibling combinators(+) and :has()πŸ‘‡ :is(.block:hover, .block:fo...
The last thing to do is apply that to the blocks themselves.

I'm also doing something a little fun here too πŸ˜…

Because the blocks are laid out with flexbox, I can use the --lerp value to alter the "flex" of each block πŸ’ͺ And the translation of each item 🎈 .blocks {   display: flex; ...
But, how did I generate those "--lerp" values? The answer is @greensock πŸ’ͺ

It has an awesome utility for distributing values using easing curves which is exactly what I needed πŸ™Œ

I used that to build this demo that generates the code πŸ€“

πŸ‘‰ codepen.io/jh3y/pen/ExEJM… via @CodePen
If you wanna check out the GSAP utils, check them out here!

The one for this was "distribute" 😎

greensock.com/docs/v3/GSAP/g…
For more on CSS :has(), check out the article I wrote for @ChromiumDev πŸ™

There are plenty of use cases in there and I'm sure there are still plenty of awesome use cases that people will discover as :has() lands in all the browsers πŸ™Œ

developer.chrome.com/blog/has-m105/
As for that browser support, it's almost there! 🀏

We've got :has() in Safari already and it lands in Chrome version 105. It's also behind flags in current Chrome releases and Firefox 😎

Exciting times! 😁

caniuse.com/css-has
And that's it!

Some weekend and evening tinkering led to putting this together πŸ˜…

The motivation was using easing curve values inside custom properties πŸ€“

Any questions, hit me up! πŸ™

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with jhey Κ•β€’α΄₯β€’Κ”

jhey Κ•β€’α΄₯β€’Κ” Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @jh3yy

Sep 13, 2023
Future CSS Tip! 🍏

You could create those Apple-style dynamic CTA reveals with container style queries and scroll-driven animations with zero JavaScript πŸ‘€ (Sticking to the #AppleEvent theme)

.cta {
animation: activate both, activate reverse;
animation-timeline: --section, view();
animation-range: entry, cover 50%;
}

keyframes activate {
0% { --active: 0; }
100% { --active: 1; }
}

@ container style(--active: 1) {
.cta__bloom {
scale: 0.99;
transition: scale 0.5s var(--back); /* πŸ‘ˆ linear() */
}
.cta a {
scale: 1;
grid-template-columns: var(--content-size, auto) 36px;
transition: scale 0.2s 0s, grid-template-columns 0.5s 0.6s var(--elastic);
}
}

There's a fair bit of code here 🀯

But, the idea is this...

1. Use a scroll-driven animation scoped to each section for each CTA to change a custom property value (--activate) between 1 and 0.
2. Use a container style query to dictate the transition sequence for each moving part making use of transition-delay.
3. Make use of linear() easing to get the right effect ⚑️

It's wild to put all these APIs together and see what's possible. There are likely some spots to tidy this up πŸ’― These are powerful combinations for sure though! πŸ’ͺ

@CodePen link below! πŸ‘‡
Here's that @CodePen link! πŸš€

You'll need to be in Chrome 115+ to see everything working as it should 🀞

We're combining:
– Scroll-driven animation
– linear() easing
– Container style queries

codepen.io/jh3y/pen/zYyzY…
@CodePen Missed the details around linear() easing functions?

Here's the post I made about them πŸ˜‰

The @smashingmag article should be landing this week I think πŸ€”

Read 5 tweets
Aug 23, 2023
CSS Tip! ✨

You can create icon sprite animations using the steps() animation-timing function πŸ€™

You could use this to create little icon button animations, etc. 😎

But how do you do it? Like this πŸ‘‡

button img {
object-fit: cover;
object-position: 0 0;
}

The image is a sprite strip of the frames in the animation. To animate the frames, you do something like this:

[aria-pressed=true] img {
animation: play 0.5s steps(20) forwards;
}

@ keyframes play {
to {
object-position: 100% 0;
}
}

We are toggling aria-pressed in our scripts to show a pressed state and we can then fire the animation to play our sprite πŸŽ‰

Check out the video that breaks things down a little bit

@CodePen link blow! πŸ‘‡

Here's that @CodePen link! πŸš€

This was a bunch of fun to make. In fact, the hardest part was making the sprite πŸ˜‚

codepen.io/jh3y/pen/KKbpe…
Arguably one of the coolest parts about this sprite animation is using a CSS filter to change the color 😎

This is how the animation looks from the demo and we combine scale and filter to change the color and bump the icon size without editing the SVG itself πŸ€“

@ keyframes sprite-play {
75% {
scale: 1.25;
}
100% {
opacity: 1;
filter:
invert(0.4)
sepia(1)
saturate(20)
hue-rotate(140deg)
brightness(1);
object-position: 100% 0;
}
}

@cassiecodes covers this technique really well in this @css article πŸ‘‡

Read 4 tweets
Feb 28, 2023
Have you tried out the View Transitions API? ✨

Been playing have a play with it this evening πŸ‘€

A bit of JavaScript Web Animations API usage for those rainbow lines but sets me up for another demo idea! πŸ’‘

Repo && deets πŸ‘‡
The View Transitions API is gonna be a game-changer for the flexible ways in which you can use it with UI πŸ’―

For a guide to the API, @jaffathecake has you covered πŸ‘‡

developer.chrome.com/docs/web-platf…
I've put together a little Astro project for some of the experiments I put together with the API πŸ€“

I'll get around to making some more UI things with it. I keep meaning to write up this card shuffling demo from last year πŸ˜…

πŸ‘‰ github.com/jh3y/view-tran…

Read 4 tweets
Nov 11, 2022
CSS Tip! πŸš€

Use custom properties to power parallax effects 😎

Use JavaScript to pass the pointer position to CSS. Let CSS handle the rest, moving things at different rates πŸ’ͺ

card:hover{
rotate: calc(var(--ratio-y) * 50deg);
}

Play with card effects ✨

Demo link below! πŸ‘‡
Here's that @CodePen link! ⚑️

It's kinda hard to explain everything going on here in one tweet πŸ˜…

The magic part is how you can use JS to work out something for you and then let CSS do the rest, you're decoupling them in a way.

Let's go over it πŸ‘‡

codepen.io/jh3y/pen/wvXvE…
First, the JavaScript πŸ‘€

It's this. Grab the pointer position, and work out the ratio that the cursor position is in relation to the card size. It's gonna be between 0 and 1 πŸ€™

Next up, CSS πŸ‘‡ const CARD = document.querySelector('.card')  const UPDATE =
Read 5 tweets
Oct 6, 2022
CSS Tip! ✨

You could use :has() combined with sibling combinators and other things to build a working 3D CSS Connect 4 πŸ€“

.col:has([row=p-1]:checked) +
...
.col:has([row=p-1]:checked) ~ .result {
--win: 1; --winner: var(--p);
}

Demo link below! πŸ‘‡
Here's that @CodePen link! πŸš€

The performance of CSS :has() is pretty incredible. There's another demo I'll share where it does some pretty "extra" stuff and it handles it like a champ πŸ’ͺ

codepen.io/jh3y/pen/Jjvap…
The amazing thing about building things like this is that it challenges the way we think about using certain tools. This is one of the points I made in my talk today at @webdevconf πŸ’œ

pic: @JoshTumath Jhey on stage at WDC presenting his talk. The stage screen s
Read 4 tweets
Oct 5, 2022
Wild to think how close we are to almost being able to build this with CSS alone 🀯

This is a version I built with JavaScript using GSAP ✨

It does have perks like infinite smooth scroll πŸ‘€

But, think I'll try building a CSS version without πŸ€“

Demo link for this one below! πŸ‘‡
Here's that @CodePen link! πŸš€

You can spin that mouse wheel to your heart's content on this and it'll keep going πŸ˜…

codepen.io/jh3y/pen/WNRvq…
Here's the accompanying @css article too! πŸ€“

Learned a whole bunch from the peeps over at @greensock when making this πŸ™ Really made me think differently about how I approach some animations

css-tricks.com/going-meta-gsa…
Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(