Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

To avoid any confusion, let's add a tooltip showing the current value. An ugly one that bounces in all directions! Now, the range slider is perfect, no one can say otherwise!

25,285 görüntüleme • 2 ay önce •via X (Twitter)

3 Yorum

Alexander ‘Gruni’ Grunert profil fotoğrafı
Alexander ‘Gruni’ Grunert2 ay önce

That the tooltip stays in position until you let go is genius.

anotheryou profil fotoğrafı
anotheryou2 ay önce

Haha, almost built that today XDD (claude misunderstood which part should snap to the measure point and which should follow the mouse and on what axis'. Well I might also have mixed up x and y at some point, but that resulted in different hilariousness)

Philipp Hager profil fotoğrafı
Philipp Hager2 ay önce

The slider should roll down to stable lower positions if left on slopes or higher positions though… 🤣

Benzer Videolar

CSS in 2024 🤯 You can create a range slider with updating value tooltip and color changing track without using any JavaScript 🤯 ::-webkit-slider-thumb{ view-timeline: --thumb inline; } Scroll animation on the slider thumb that animates a number between the "min" and "max" of the range 😅 @​property --value { syntax: ' '; } @​keyframes sync { to { --value: 100; }} Tie that up to the contain animation-range ⚡️ .control { animation: sync both linear reverse; animation-timeline: --thumb; animation-range: contain; } Hoist the view timeline so the tooltip can use the value too! :root { timeline-scope: --thumb; } Then use it in the counter which goes in the tooltip 😇 .tooltip { counter-reset: val var(--value); } .tooltip::after { content: counter(val); } Then the accent color is based on the value too 🎨 [type=range] { accent-color: hsl(var(--value) 90% 65%); } The magic from the quoted post is using anchor positioning on the range thumb to position that tooltip 👏 Never thought of that when working on the spec for this API. This API lets you tether elements to other elements. Using the pseudo is a clever move! ::-webkit-slider-thumb { anchor-name: --thumb; } .tooltip { position: absolute; anchor-default: --thumb; left: anchor(50%); bottom: calc(anchor(top) + 25%); } The last piece is the little bounce transition... OK. I used a line or two of JavaScript for that 🙏😬 const updateDelta = ({ movementX }) => { document​.documentElement​.style.setProperty('--delta-x', movementX) } document.body.addEventListener('pointermove', updateDelta) But only so you can pass the movement delta to CSS and then reset the position with linear() to get that bouncy transition 😎 .hint { rotate: calc(clamp(-60, var(--delta-x) * -1, 60) * 1deg); transition: rotate 1s linear( 0, 0.2178 2.1%, 1.1144 8.49%, ... ); } Should probably do a video on this one. Lots of little tricks to break down with it for sure! 💯 As always, any questions, let me know! Also, this one only works in Chrome Canary with the Experimental Web Platform Features flag enabled ✅ This one almost feels like rocket science ha 🚀 CodePen.IO link below! 👇

jhey ʕ•ᴥ•ʔ

251,867 görüntüleme • 2 yıl önce