Implementing an animated progress bar for tracking article read progress.

I'm trying to animated a bar using css, the default continuous bar works fine, but I have a list of divs (say 10 divs) that are little squares in a row, and I want to paint x number of squares based on how much the css bar is animated. say 50% of the bar is animated so i'm at keyframe 5/10, I want to translate that progress to the number 5 and then render 5 filled blocks in my div list I'm using react and plain css. Here is my css, I took it from https://scroll-driven-animations.style/demos/progress-bar/css/ as you see on the screen, there is a red bar at the top which shows the scroll percentage (how far we have scrolled from the top of the article. and the green blocks that are filled are showing the same progress but in discrete units. (it's currently not working propertly the filled in ones are just a random number) in my latest approach I tried making a new css @property (--scrolled) and inside the keyframes interpolated between 0 and x (say 20 blocks) in my animation keyframes, but I'm not able to access the updated --scrolled property with js, I'm not even seeing it be updated on dev console. Anyone got any ideas for what I'm trying to achieve?
No description
No description
4 Replies
clevermissfox
clevermissfox13mo ago
Rake a look at KPs recent videos on scrolll-timeline! ITs not toally supported so may not be the solution right now but good to know about or if you dont need to take to production.
clevermissfox
clevermissfox13mo ago
Kevin Powell
YouTube
True parallax with CSS-only is now possible
https://kevinpowell.co/courses?utm_campaign=general&utm_source=youtube&utm_medium=cssparallax 👈 Interested in levelling up your CSS game? I’ve got courses! Parallax effects can be cool, but I’m always told the CSS-only solutions aren’t “true” parallax. Well, thanks to scroll-timeline: scroll(), we can now create true parallax effects without on...
Kevin Powell
YouTube
JavaScript Scroll Animation Tutorial | Web Animations API + ScrollT...
Scroll-based animations used to be pretty hard and usually meant turning to a library. With the Web Animations API and ScrollTimeline, it's now surprisingly easy to do! 🔗 Links ✅ The Polyfill: https://github.com/flackr/scroll-timeline ✅ The Discord community: https://discord.gg/nTYCvrK ✅ Doing this with CSS only (@scroll-timeline): https://you...
Kevin Powell
YouTube
Scroll-linked animations only using CSS?! Featuring Adam Argyle
None other than @AdamArgyleInk has jumped on to help teach me about @scroll-timeline! Make sure to give Adam a follow on Twitter and check out everything he's up to (links below). Animations are part of CSS, but we often have to use JavaScript to trigger the animations themselves. Well, that's starting to change now with the help of @scroll-ti...
Elemelon
ElemelonOP13mo ago
figured it out! thanks I was already using scroll timeline, i was having trouble taking the value of scroll timeline in any given keyframe and using it to calculate progress in terms of number of blocks to highlight. I ended up using a css variable inside @keyframe, and on every scroll reset a state variable based on number of the css variable that I grabbed with getcomputed style. it doesn't seem like a good idea to rerended a list of elements on every scroll event but it seems there is no better way to achieve what I'm trying to achieve
Elemelon
ElemelonOP13mo ago
here is the implementation in full for future reference, ignore crossed out lines, they are N/A
No description
No description
No description
No description
No description
No description
Want results from more Discord servers?
Add your server