Can I copy this text reveal scroll effect with CSS-only?
HTML-код
- Опубликовано: 31 май 2024
- kevinpowell.co/courses?... 👈 Looking to up your CSS game? I have a range of free and paid courses.
My editor (who you can find here if you're looking for one: levicurry.com/ ) saw a fun text reveal animation on a site he came across and shared it with me, thinking it might make for a fun video, and the timing couldn't have been better with all the scroll-timeline content I've been doing lately!
🔗 Links
✅ Need an editor? levicurry.com/
✅ The orginal site I’m copying: shop.boox.com/en-ca/products/...
✅ My deep dive into scroll-timeline and range: • Incredible scroll-base...
✅ Creating a parallax effect with scroll-timeline: • True parallax with CSS...
✅ Other “can I clone this” videos: • Can I build it?
⌚ Timestamps
00:00 - Introduction
00:45 - What we’re starting with
01:18 - Creating gradient text
03:48 - Creating the animation
05:54 - Realizing I need inline elements
07:44 - Fixing the animation timing
15:22 - Making the gradient match the original version
#css
--
Come hang out with other dev's in my Discord Community
💬 / discord
Keep up to date with everything I'm up to
✉ www.kevinpowell.co/newsletter
Come hang out with me live every Monday on Twitch!
📺 / kevinpowellcss
---
Help support my channel
👨🎓 Get a course: www.kevinpowell.co/courses
👕 Buy a shirt: teespring.com/stores/making-t...
💖 Support me on Patreon: / kevinpowell
---
My editor: VS Code - code.visualstudio.com/
---
I'm on some other places on the internet too!
If you'd like a behind the scenes and previews of what's coming up on my RUclips channel, make sure to follow me on Instagram and Twitter.
Twitter: / kevinjpowell
Codepen: codepen.io/kevinpowell/
Github: github.com/kevin-powell
---
And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!
Turns out Chrome dropped the requirement to for the -webkit- prefix with v120, which is why this worked without it. If you're worried about browser support, you're probably best including both the prefixed and unprefixedd versions.
Hi! Please tell me where i can read about this change? Sorry for the bad English, but you're being watched all over the planet, I think that's okay =)
Nice work! Anywhere we can find this code example? I don't think I can see it on Codepen
Regarding the magic number issue, my assumption is that the difference between the animation ranges is a variable of the height of the h2 element. Like, if h2's background starts and ends animation when the top edge of its css box passes the limit our vh values set, then there is technically a gap between when the h2 is done with its animation and when p starts its own. Just a wild guess.
Agreed, maybe end the h2 with contain and start the paragraph with cover with the same value so that header finishes just as p starts? That should deal with the unknown size of the h2. This is all completely new to me, so I could be totally wrong.
Would be good to see if this would solve the issue with a calc, 30vh - h2 font height.
Same thoughts here too!
DId someone tried it to confirm?
Although we still rely on an arbitrary number that would harder to "guess" if the text line broke into two or more due to viewport width.
Most likely the h2 has 100% width, so the background animation goes from one edge of the screen to the other edge (Not just the width of the letters).
We cant see it because of the clipping, but that would explain the delay between the animations.
@@WakeMtzI don't think so, the animation is done on the spans inside the h2 and p, not on the h2 and p themselves, and they aren't set to 100% width.
Decided that I had done enough navel gazing and forked the codepen then made the changes I discussed, and it's close, but not quite spot on. The text in the paragraph starts filling in when the "a" at the end of "Palma" is about half full. On the other hand, if the header overflows into multiple lines, it adapts better than the magic number version. With a three line header, the paragraph starts filling at just about the same time the last letter of the header starts filling in.
My first hunch was because of margin collapsing, as in the Chrome inspector, the content boxes of the two spans slightly overlapped, but I can't find any vertical margins to cause that.
If you're curious to see how it looks, search codepen.io for "css-only text reveal on scroll" with forks enabled, mine is the one by "EricGeek"
Love these "real world" examples, Kevin. It would be cool if we had videos like these from time to time. Happy New Year
Damn, you make the impossible possible Kevin. I can't even think of doing such things using pure CSS... JUST WOW 💕🦄
To be completely fair, the original has the reveal applied one word at a time, so it’s a very different effect…
My thoughts too
Yep, I think they were for this effect because the device they are promoting wouldnt be more akin to display word by word. I think the smooth version wouldnt even show nicely on said device. They are chinese, so likely they developed it with chinese localization and character set - one character at a time
I think the way to avoid magic numbers is to use cover for the start and contain for the end. That way, the first animation ends when the bottom of the h2 reaches the specified position and the second animation starts when the top of the p reaches that same position.
Thanks Kevin. I would love to see more of such videos. ❤
Happy new year 🎉
I first thought of making a gray overlay that scrolls away.
But this way is more to my liking.
Thanks.
I feel like you could just use contain for the headline and cover for the text. That should mean it starts the animation for the headline once its fully visible and start the animation for the text, once it enters the viewport, which I suppose means, if their containers are touching, happens at the same time and therefore you could use the same numbers?
i agree. "contain" basically is basing off the bottom of the element, and cover off the top (if you're scrolling down at least), so that would work.
Thanks for making videos like this one it really helps me learn new things.
You always seem like you're just having a blast doing these!
Dude you genius. I am full time backend developer but I can’t stop watching your videos 😂🙏
Always love your video and everytime there is something new for me to learn
Kevin, I love your videos. I am learning a lot of good information thanks to you. God bless you :)
The simple fact that you're facing a real-world-css-problem and trying to deal with it in real-time is one of that things that better bond you to your audience. The "only" (realy? 😅) difference is that you find - and know - the solutions in a few minutes (maybe seconds) instead of days or weeks, like some of your audience (me included hahaha). Thank you for bring all your great content and skills as always!
Quite an interesting format of video💪🏻👍🏻👍🏻👍🏻
h2 span should be contain, essentially meaning the bottom reaches the number, then p span should be cover, essentially meaning the top reaches the number. You never tested with those settings.
Or maybe calc(20vh + line-height of h2)
Awesome ! I love that kind of video : I'm learning new stuff about css. I can do something pretty. AND I can see the way you are thinking to create css.
wow, so many new interesting things for me to learn this new year!
Kevin you are a pure css lover .
Thank you for sharing 😊
Love this, I think Bramus Van Damme is the one who can explain the range stuff the best ;)
You’re the best!
I enjoyed watching you work through this and listening to your thoughts 🙂 also the little "it worked!" because that's exactly how I feel when I figure things out 🤣
You rock! I have an idea, probably animation range start must be the same number - the height of the paragraph, so if you use js for that and will set custom property for that, it would work probably and the event will start ideally, isn't it? Without js idk how to do that without magic numbering:)
I was trying to do this a week ago with just HavaScript and tailwind. Got close, but didnt quite get it lol. Thanks man.
bro make such a rich animation hppy new year website 🎉🎉🎉🎉🎉
CSS magician ❤
best video before i go to sleep, i ll dream this.
Love the video! If you're looking for stuff to do, there's a challenge on frontend mentor called countdown timer that was WAY trickier than it looks on the outside. It was a lot of fun and I'd love to see your approach
Beautiful!! Only CSS!!
I was wondering if you would do a version where the animation highlights the paragraph word-by-word like in a original example (I guess that is only possible with JS). Turns out your gradient version looks smoother and nicer, great video.
wow that's amazing
Love this series! Can Kevin Code It!
Awesome!
If the elements are stacked with no margin probably what would work is the top one has animation-range-end: contain (plus offset) and the next has to be animation-range-start: cover (plus same offset as). I didn't test it so idk if it would work... if so there is no need for magic numbers
You can also try experimenting with view-timeline-name. I think you can use the same timeline for both the h2 span and the p span, for example, define a named timeline for the h2 element, and use that timeline to define the event for both. You will probably not need magic numbers, because now view() creates two different timelines and the numbers do not match.
Believe me, I've been literally begging for vids on the View-Timeline API but this was just about Scroll Driven Timelines. The real magic will be when he uses both!
Hey can we add more delay for animation if i adding animation-delay method it was not showing any effect is there any way to fix this ?
Ok, now, reveal word after word, like the original;)
U’re great, keyframes usely helps with several animations..
Thanks!
Thank you so much!
Amazing
i wonder if there is a way to make this work with for example sup elements inside, which have a position:relative, or transform: translate on them.
Genius!
please i nned a help, background-clip text need color to be transparent or not ? if i set color to gray for eaxmple, background-cl;ip not working for me, can i someone help me please
can i control background video with css scroll?
Hi Kevin, I have one question about sass and I can;t find the answer.
Let's say we have a button with data-theme="primary" and i want to use this value in scss to pass it to my mixin
.button {
@include myFancyMixin(
Great job and a great effort, I just noticed that the original fills word by word idk
I wonder if box-decoration-break would make this more controllable... Gonna need to try that one out myself. :D
I'm surprised you didn't add a bunch of outlines to the elements with changes in the outline colors to debug when things were triggering.
Nice work!
But, I think you missed something. The other site animates whole word at a time.
For a non-hardcoding sol u could prolly put all the text in one p tag n for the heading put it in a span with large font size. Not gr8 for acessibility but 🤷🏼
I think i like it better with the blue to red gradient
Hello Kevin, Happy Newyear! Thanks a lot for this amazing animation and the insights. I tried to apply the same inside Elementor using the html widget, however the animation is not working. I was able to replicate it in an html page. However in elementor its seems something is conflicting.
I have an issue in Visual studio code where the delete button now wont delete my css, just started last night. Can you help?
Very cool! I’ve never been able to make background-clip: text work without prefixing it. It’s like magic! Which browser are you using here ?
Chrome, which surprised me when it worked, lol. Looks like they dropped requiring the prefix with v120
@@KevinPowell 🌟🌟🌟
Hi Kevin.
Can u explain how to text-overflow ellipsis without "white-space: nowrap"?
Your solution is certainly nice, and is still a good exercise regardless, but a bit of OCD kicked in and had me mentally shouting at the screen that the orignal your copying is 'stepped' that is, it changes the color one word at a time, not in a gradiant like you did. Wonder if that is at all possible in CSS only? I'm guessing it would need JS.
I actually like my version better, lol. But yeah, I think you need JS to do it word by word.
I am so proud of you....this is so cool
👌👌🔥🔥 Just Wow😯
Maybe calc(20vh + 1em) or something like that 🤔 ?
Got it to work perfectly by putting display inline only on the paragraph. Put onAnim class on both h1 and p then it flows without magic numbers.
```css
p {
display: inline;
}
.onAnim {
color: hsl(0 0% 100% /0.3);
background-image: linear-gradient(90deg, red, blue);
background-clip: text;
background-size: 0% 100%;
background-repeat: no-repeat;
animation: scroll-reveal linear forwards;
animation-timeline: view(80% 15%);
}
@keyframes scroll-reveal {
to {
background-size: 100% 100%;
}
}
```
Thanks, this will be very useful once browser coverage is optimal.
i wonder how does it work when you maximize the screen window
Cool 🎉
Is there any way to do it "word by word" like the original website with CSS only?
Make the entire thing a span for the animation-range-start and animation-range-end !
Original site was highlighting the whole words. I was very interested how you would do it in css, but your exapme highlights any part, including partial letters. Can you fix that?
Could you please make a tutorial on how to deal with tables with many columns on mobile view? I'm having trouble with tables that overflow when the viewport gets smaller. I would really appreciate it.
very cool video btw, i've been looking for a text reveal on scroll css only video for a long time. love your video.
Great Explanation Sir......Can You Create A Specific Videon On CSS perspective.....And 3d Zoom Animation On Scrolling.....And Other Great Things We Can Do With Css❤
Hi Kevin, do you have a link to this test, thanks.
I thought you’d use box-decoration-break: clone. That would theoretically work, but depends if the animation treats each cloned background as its own animation.
I wonder if that would work 🤔. I'd been planning another video looking at an underline gradient for links, so I knew I could just have them as inline elements 😅
Hi kevin, love your tutorials ! Can you do it with the color and text content changing when hovering ?
To change the text itself, you either need different layers, and remove the opacity of one when hovering, or JS to actually change the content itself.
Instead of using magic numbers I think you could have used `calc(20vw + var(--_h2-font-size))` ?
Is it possible with CSS-only to run the animation only once? like on the first time user scrolls do a funcky animation but don't do it again? I know that's possible with adding some JS.
This timing weirdness is bevause the animation is going over background of the element as a hole so it is timed over the box width of that h2 and not just the text.
I wonder if you made the box better fit the text if less magic would be required. Just a thought. Nice work!
This is one awesome real-world example, Kevin.
One question for a CSS novice like myself, why does the inline change fix the way the animation works at about 6:00 ?
I could have never come up with that solution so maybe I am missing some key information on why the span changes the animation direction from top-down to left-right.
Thank you
For a block element the gradient is applied to the whole rectangle. For inline text it only covers the line-height, and will wrap with the line of text.
I should have gone into more detail there, but Shaun explained it nicely :)
@@shaunpatrick8345 Thank you very much for the explanation
Wasn't the original "revealing" by entire words? Your solution reveals half of the words.
Yeah but no way to do that with CSS only... mine doesn't do half words, it just gradually reveals as you scroll :)
Do i need to install or update anything to be able to creat this i was trying out scroll animation and it wasnt working
This should work in Chrome, but it's behind a flag in Firefox and not currently supported in Safari.
Why this things doesn’t work on my ios device? Please help me out the same thing happened to fade in scroll animation while using view()
iOS is Safari, even if you're using other browsers, it's just different skins of Safari, as they all have to use the webkit engine under the hood on iOS. You'd need to use the Polyfill, and it might take a bit of tweaking to get it to work there.
If animation-timeline was accepted by my browser I would have tried putting the animation on the wrapping div and maybe using display inline.
My guess is it wouldn't work, but I wonder how it wouldn't work. I wonder if it would take each children as a single line and deal each of them like a normal block... grrrr I wanna seeeee
I guess if you subtract the height of the first element from the start point it will match in timing. This will solve problems with changing font sizes.
Sorry. Adding the height to the start point.
Welll it's not the same this one is revealing everything partially, it's like at some point only half the word is white, in their version a word is either completely grayed out or completely white. I do admit though that it's crazy hard to do it like that with only css just use javascript in that case.
word by word either requires JS or wrapping every word in a span and magic numbering everything, which I wasn't about to do 😅
Is it possible to have more smooth effect, using gsap that reveal is really smooth
I think mine is about as smooth as it can get 🤷
@@KevinPowell sorry, what I meant was fade effect is letter by letter
first I try by my own it then Ill watch the video
gsap premium has something similar, but this one's for free yay!
Cool. But you really need to check what happens with different window sizes (height, width...) and different font sizes. I have a feeling it might fall apart.
Really cool exercise! The boox site seems to apply the effect one whole word at a time, though. Would it be possible to do the same and keep it CSS-only?
No, I think for that you'd need JS. Or a lot of spans and magic numbers 😅
Even if you use JS, you'll 😢end up just building those spans at runtime, I think
I cant get the animation-timeline: view() to work?? any idea?
It seems that animation-timeline is not supported on Safari if you are using that.
The original one actually did it word by word, would be really interesting how you could do that instead of an overlay that is just overlayed.
Sir please make header scroll animation using css
Maybe you can use something like `1lh`?
I don't get why inline element started the text to get the nimation line-by-line
Is there a css only fix for firefox?
No, it's simply not supported yet. It's behind a flag though, so it shouldn't be too much longer, hopefully.
@@KevinPowell Bro, thank you very much for giving us your knowledge, I already implemented it in my web project, but the only problem I have with the animation is that on smartphones it makes me scroll to the sides, I tried to eliminate it by setting overflow. : hidden from the father container, but the text animation is lost with that property. Can you help me? Greetings from mexico friend 😃
Something new to learn...
7:00
14:30 - Given that the range-start is offset, the second (paragraph) cover/contain offset needs to include header height, and that gets rid of magic numbers.
kevin is giggling
Helloooo sir Kevin, what channels do you follow for JS ?
Web Dev SImplified and Dave Gray are both great :)
Thank you sir !!
it is to early to use in reall projects the scroll() and view() becasue caniuse supprot just 66.8% - not enough )
❤