Skip navigation
CSS Tip! 🤙 You can use mask-composite and some JavaScript to create this pointer proximity following…
0:00 / 1:09

CSS Tip! 🤙 You can use mask-composite and some JavaScript to create this pointer proximity following…

jhey ʕ•ᴥ•ʔ

@jh3yy149K followers

Visit on X
7,124 likesDownloadOriginal post

1,181,113 views

CSS Tip! 🤙 You can use mask-composite and some JavaScript to create this pointer proximity following glow border ✨ .glow { mask-composite: intersect; mask-clip: padding-box, border-box; mask: linear-gradient(#0000, #0000), conic-gradient(#0000 0deg, #​fff, #0000 45deg); } The trick is to mask a background-image with a combination of mask layers. mask-composite: intersect; means the mask used will be the intersection of the layers 🔥 use source-in, xor; in browsers that don't support intersect; In this demo, you can use pseudoelements and rely on scoped custom properties to do a lot of the heavy lifting for you 🙌 Once you've masked the background, you need to update the starting angle of the conic-gradient on pointermove 👆 You can work that out by getting the center point of each card and then calculating the angle between that and the pointer with Math.atan2 🤓 let ANGLE = Math.atan2( event?.y - CARD_CENTER[1], event?.x - CARD_CENTER[0] ) * 180 / Math.PI ANGLE = ANGLE < 0 ? ANGLE + 360 : ANGLE; CARD.​style.setProperty('--start', ANGLE + 90) You plug that into your conic-gradient mask as a custom property accounting for --spread ⚡️ conic-gradient(from calc((var(--angle) - (var(--spread) * 0.5)) * 1deg), #000 0deg, #​fff, #0000 calc(var(--spread) * 1deg)); To get the blur, you apply a blur to the glow container on each card 🤙 .glows { filter: blur(calc(var(--blur) * 1px); } That's it! Layers of masks that are clipped and composited before being blurred 😎 The added trick is to fade each one in when the pointer is in the defined proximity of the card. For example, don't show unless within 100px of a card. You can see that in the video. Check out the JavaScript code for that 🫶 Couldn't resist making this one 😁 CodePen.IO link below! 👇

11 Comments

Comments from the original post on X (Twitter)

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Here's that @CodePen link! 🚀 Can't resist a glowy border demo 🙃 Was meant to be finishing something else this evening but that'll have to wait I guess 😅

    205 likes

  • Dave Ashworth's profile picture

    @daveashworth

    This is the kind of magic I’m here for 🙌

    11 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Thanks Dave 🙏 Appreciate it. Sometimes I throw these together and think "Meh" 😅 The video compression kinda butchers it and it's hard to explain the moving parts but no need for overlays, etc. 🤙 Can clip away the parts you don't need and then apply a blur to get the glowy border ✨

    5 likes

  • pavi2410's profile picture

    @PavitraGolchha

    I need a jheyGPT to write my CSS

    6 likes

  • John Lindquist's profile picture

    @johnlindquist

    I've really gotta add some fancy glowing gradients to Script Kit in the next release...

    4 likes

  • Natko Hasic's profile picture

    @natkohasic

    You are killing it, just your tweets are better than any frontend course out there.

    4 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Thanks Natko! 🙏 We need to get them all onto their own website, stat! 😅

    2 likes

  • Fabrice Lejeune's profile picture

    @fabricelejeune

    Years ago I had to do this same effect with lots of SVG and JavaScript 😅

    2 likes

  • Louis @ YM4's profile picture

    @YM4design

    Damn thats a lot of tabs haha

    2 likes

  • Narek's profile picture

    @NarekHakobyan

    @jh3yy The scroll is lagging when page has conic-gradient, do you have any idea how to solve it?

    2 likes

  • jhey ▲🐻🎈's profile picture

    @jh3yy

    Impossible to say without seeing a demo. But, it's fine for this demo as people have shown me their uses of it in production 🤙

    1 like