Can I copy this text reveal scroll effect with CSS-only?

Поділитися
Вставка
  • Опубліковано 26 лис 2024

КОМЕНТАРІ • 171

  • @KevinPowell
    @KevinPowell  11 місяців тому +70

    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.

    • @ВладимирДолгуев
      @ВладимирДолгуев 10 місяців тому

      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 =)

    • @Streamerabi
      @Streamerabi 10 місяців тому

      Nice work! Anywhere we can find this code example? I don't think I can see it on Codepen

  • @darkbluebossa
    @darkbluebossa 11 місяців тому +50

    Love these "real world" examples, Kevin. It would be cool if we had videos like these from time to time. Happy New Year

  • @Chevindu
    @Chevindu 11 місяців тому +51

    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.

    • @erics2133
      @erics2133 11 місяців тому +4

      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.

    • @simonwxyz
      @simonwxyz 11 місяців тому +5

      Would be good to see if this would solve the issue with a calc, 30vh - h2 font height.

    • @xphstos_
      @xphstos_ 11 місяців тому +1

      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.

    • @WakeMtz
      @WakeMtz 11 місяців тому +1

      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.

    • @erics2133
      @erics2133 11 місяців тому +2

      @@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"

  • @zygoloid
    @zygoloid 11 місяців тому +8

    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.

  • @Shaheer-xs5os
    @Shaheer-xs5os 11 місяців тому +18

    Damn, you make the impossible possible Kevin. I can't even think of doing such things using pure CSS... JUST WOW 💕🦄

  • @RANKKY9
    @RANKKY9 11 місяців тому +17

    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?

    • @StevenDavisPhoto
      @StevenDavisPhoto 11 місяців тому +1

      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.

  • @avertry9529
    @avertry9529 11 місяців тому +1

    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.

    • @RaisingWEB
      @RaisingWEB Місяць тому

      Yea, I have tested and it and it worked.

  • @jordybaylac9470
    @jordybaylac9470 11 місяців тому +1

    Dude you genius. I am full time backend developer but I can’t stop watching your videos 😂🙏

  • @santoshparker8681
    @santoshparker8681 9 місяців тому +1

    Kevin you are a pure css lover .

  • @thildamoon
    @thildamoon 11 місяців тому +3

    I first thought of making a gray overlay that scrolls away.
    But this way is more to my liking.
    Thanks.

  • @IAmSamuelCharpentier
    @IAmSamuelCharpentier 11 місяців тому +87

    To be completely fair, the original has the reveal applied one word at a time, so it’s a very different effect…

    • @pcabdulbasith
      @pcabdulbasith 10 місяців тому +7

      My thoughts too

    • @HolgerNestmann
      @HolgerNestmann 10 місяців тому +3

      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

  • @m3ndecsgo
    @m3ndecsgo 8 місяців тому +2

    You’re the best!

  • @lostpixelspodcast
    @lostpixelspodcast 11 місяців тому +13

    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.

  • @ed1nh0
    @ed1nh0 10 місяців тому

    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!

  • @_fuji_studio_
    @_fuji_studio_ 11 місяців тому +1

    bro make such a rich animation hppy new year website 🎉🎉🎉🎉🎉

  • @ahmedel-sherif9327
    @ahmedel-sherif9327 4 місяці тому

    Regarding the magic number issue, my assumption is that the lag between the two animations is because the h2 is taking the full width of the container, so it resumes to fill the rest of the element (which is not having text in it).
    solution: display the h2 as an inline-block element instead of block

  • @Paciffic
    @Paciffic 11 місяців тому +3

    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.

  • @Maria_Moon_Angel
    @Maria_Moon_Angel 7 місяців тому +1

    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 🤣

  • @antonztxone
    @antonztxone 11 місяців тому +1

    Quite an interesting format of video💪🏻👍🏻👍🏻👍🏻

  • @moroccan-sahara
    @moroccan-sahara 11 місяців тому +4

    Or maybe calc(20vh + line-height of h2)

  • @NottsKnots
    @NottsKnots 11 місяців тому +5

    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.

    • @KevinPowell
      @KevinPowell  11 місяців тому +2

      I actually like my version better, lol. But yeah, I think you need JS to do it word by word.

  • @MrJettann
    @MrJettann 11 місяців тому +2

    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:)

  • @harikotha7
    @harikotha7 11 місяців тому +1

    Thanks Kevin. I would love to see more of such videos. ❤
    Happy new year 🎉

  • @CommDao
    @CommDao 11 місяців тому

    You always seem like you're just having a blast doing these!

  • @nathangwyn6098
    @nathangwyn6098 11 місяців тому

    I was trying to do this a week ago with just HavaScript and tailwind. Got close, but didnt quite get it lol. Thanks man.

  • @lubosmato
    @lubosmato 11 місяців тому +1

    CSS magician ❤

  • @skull2661
    @skull2661 11 місяців тому +1

    Thanks for making videos like this one it really helps me learn new things.

  • @sonalirawat3731
    @sonalirawat3731 10 місяців тому +1

    Thank you for sharing 😊

  • @KostasOreopoulos
    @KostasOreopoulos 11 місяців тому +1

    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.

    • @clevermissfox
      @clevermissfox 11 місяців тому

      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!

  • @serginhodabousa
    @serginhodabousa 11 місяців тому

    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

  • @walterenriquez9443
    @walterenriquez9443 11 місяців тому +3

    Nice work!
    But, I think you missed something. The other site animates whole word at a time.

  • @bmarius05
    @bmarius05 4 місяці тому

    Maybe use contain for the h2 end and cover for the p start and set both to 30vh and it is in sync. Because once the whole h2 is past the 30vh mark, then the just enters and thats when you want to start the animation

  • @radvilardian740
    @radvilardian740 11 місяців тому

    best video before i go to sleep, i ll dream this.

  • @tmbarral664
    @tmbarral664 11 місяців тому +1

    Ok, now, reveal word after word, like the original;)

  • @danielnk2024
    @danielnk2024 3 місяці тому

    I just watch your video and try it and when I use px with animation-range-start and animation-range-end and that's work perfectly. by the way thank you for all your video that's help me a lot to learn new thing and become better.

  • @Julie-gh5ir
    @Julie-gh5ir 10 місяців тому

    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.

  • @zainmalik2812.
    @zainmalik2812. 10 місяців тому

    Always love your video and everytime there is something new for me to learn

  • @clevermissfox
    @clevermissfox 11 місяців тому +4

    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 ?

    • @KevinPowell
      @KevinPowell  11 місяців тому +1

      Chrome, which surprised me when it worked, lol. Looks like they dropped requiring the prefix with v120

    • @clevermissfox
      @clevermissfox 11 місяців тому +1

      @@KevinPowell 🌟🌟🌟

  • @TheCârtiță
    @TheCârtiță 11 місяців тому

    wow, so many new interesting things for me to learn this new year!

  • @TheJoeLopes
    @TheJoeLopes 6 місяців тому

    Beautiful!! Only CSS!!

  • @CPloj
    @CPloj 8 місяців тому +1

    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.

  • @prokhor_music
    @prokhor_music 11 місяців тому +2

    Maybe calc(20vh + 1em) or something like that 🤔 ?

  • @balaclava351
    @balaclava351 11 місяців тому +2

    Instead of using magic numbers I think you could have used `calc(20vw + var(--_h2-font-size))` ?

  • @ROL4ND-CSS
    @ROL4ND-CSS 11 місяців тому

    Love this, I think Bramus Van Damme is the one who can explain the range stuff the best ;)

  • @knickebein8112
    @knickebein8112 5 місяців тому

    Thksss a lot!!!! ive been looking for this 10hr ago

  • @berkozerdogan
    @berkozerdogan 11 місяців тому

    Kevin, I love your videos. I am learning a lot of good information thanks to you. God bless you :)

  • @mahadevovnl
    @mahadevovnl 10 місяців тому

    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.

  • @ReneJethmal
    @ReneJethmal 11 місяців тому +3

    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?

    • @KevinPowell
      @KevinPowell  11 місяців тому +2

      No, I think for that you'd need JS. Or a lot of spans and magic numbers 😅

    • @rahul9704
      @rahul9704 11 місяців тому +1

      Even if you use JS, you'll 😢end up just building those spans at runtime, I think

  • @Clonephaze2327
    @Clonephaze2327 11 місяців тому

    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

  • @jsmunroe
    @jsmunroe 11 місяців тому

    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!

  • @rishitsoneja307
    @rishitsoneja307 6 місяців тому

    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 🤷🏼

  • @skeleton_craftGaming
    @skeleton_craftGaming 11 місяців тому

    I think i like it better with the blue to red gradient

  • @Bertydude
    @Bertydude 11 місяців тому

    Make the entire thing a span for the animation-range-start and animation-range-end !

  • @youssefabdulaziz2133
    @youssefabdulaziz2133 11 місяців тому +2

    Great job and a great effort, I just noticed that the original fills word by word idk

  • @QwDragon
    @QwDragon 11 місяців тому +1

    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?

  • @P.Shivakrishna
    @P.Shivakrishna 10 місяців тому +1

    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 ?

  • @yassine-sa
    @yassine-sa 11 місяців тому +2

    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.

    • @KevinPowell
      @KevinPowell  11 місяців тому +1

      word by word either requires JS or wrapping every word in a span and magic numbering everything, which I wasn't about to do 😅

  • @MarkusErdmann-p5x
    @MarkusErdmann-p5x 11 місяців тому

    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.

    • @MarkusErdmann-p5x
      @MarkusErdmann-p5x 11 місяців тому

      Sorry. Adding the height to the start point.

  • @TheOnceAndFutureDoug
    @TheOnceAndFutureDoug 8 місяців тому

    I wonder if box-decoration-break would make this more controllable... Gonna need to try that one out myself. :D

  • @bertilow
    @bertilow 10 місяців тому

    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.

  • @alihamdane
    @alihamdane 11 місяців тому +1

    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

  • @TheMetalMag
    @TheMetalMag 11 місяців тому

    U’re great, keyframes usely helps with several animations..

  • @abdabdabd886
    @abdabdabd886 11 місяців тому +1

    Thanks!

  • @ShaunLevett
    @ShaunLevett 11 місяців тому

    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.

    • @KevinPowell
      @KevinPowell  11 місяців тому

      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 😅

  • @adityashukla9840
    @adityashukla9840 10 місяців тому

    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❤

  • @classicdrumpercussion1608
    @classicdrumpercussion1608 11 місяців тому

    wow that's amazing

  •  11 місяців тому +2

    Wasn't the original "revealing" by entire words? Your solution reveals half of the words.

    • @KevinPowell
      @KevinPowell  11 місяців тому

      Yeah but no way to do that with CSS only... mine doesn't do half words, it just gradually reveals as you scroll :)

  • @Caellyan
    @Caellyan 11 місяців тому +1

    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.

  • @abilkhairi2659
    @abilkhairi2659 11 місяців тому

    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.

  • @rubengarciajr
    @rubengarciajr 11 місяців тому

    Love this series! Can Kevin Code It!

  • @gopoo
    @gopoo 11 місяців тому +1

    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.

  • @phkoon
    @phkoon 2 місяці тому

    Hello there, Kevin!
    What would that "grid-column: breakout-left" be?
    Couldn't find anything about it in any documentation I looked.

  • @Medre
    @Medre 11 місяців тому +1

    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

    • @shaunpatrick8345
      @shaunpatrick8345 11 місяців тому +1

      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.

    • @KevinPowell
      @KevinPowell  11 місяців тому +1

      I should have gone into more detail there, but Shaun explained it nicely :)

    • @Medre
      @Medre 11 місяців тому

      @@shaunpatrick8345 Thank you very much for the explanation

  • @user-tc7sv8gs2h
    @user-tc7sv8gs2h 14 днів тому

    Many thanks for the great tutorial! How do I get this to work in Firefox?

  • @eualexslim
    @eualexslim 11 місяців тому

    Hi Kevin.
    Can u explain how to text-overflow ellipsis without "white-space: nowrap"?

  • @SonuBeast
    @SonuBeast 11 місяців тому

    Sir please make header scroll animation using css

  • @IamRandomizer
    @IamRandomizer 2 місяці тому

    h1 tag has a display block or the length of the background is greater than the text...... if you guys wana try it just remove the clip and try again

  • @shubhamvishwakarma7611
    @shubhamvishwakarma7611 11 місяців тому +1

    gsap premium has something similar, but this one's for free yay!

  • @RonaldGrootJebbink
    @RonaldGrootJebbink 10 місяців тому

    Maybe you can use something like `1lh`?

  • @faraz6912
    @faraz6912 10 місяців тому

    i wonder how does it work when you maximize the screen window

  • @rahilkhan3079
    @rahilkhan3079 10 місяців тому

    Something new to learn...
    7:00

  • @pixiedev
    @pixiedev 11 місяців тому +1

    first I try by my own it then Ill watch the video

  • @utvikler-no
    @utvikler-no 11 місяців тому

    Awesome!

  • @gro967
    @gro967 11 місяців тому +2

    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.

  • @h1sname1sunknown
    @h1sname1sunknown 11 місяців тому

    Genius!

  • @anmolsharma4049
    @anmolsharma4049 11 місяців тому +1

    Is it possible to have more smooth effect, using gsap that reveal is really smooth

    • @KevinPowell
      @KevinPowell  11 місяців тому +1

      I think mine is about as smooth as it can get 🤷

    • @anmolsharma4049
      @anmolsharma4049 11 місяців тому

      @@KevinPowell sorry, what I meant was fade effect is letter by letter

  • @WorshipMinistryTraining
    @WorshipMinistryTraining 4 місяці тому

    Can I do this with one word at a time instead of one character at a time?

  • @MrNathansamson
    @MrNathansamson 11 місяців тому +1

    Well the real world did it word per word (or even a couple of words at the time). You might like it better speed wise, but especially when you stop scrolling and half a letter is done, it looks weird.
    I guess doing it letter by letter is not possible using CSS...

  • @avertry9529
    @avertry9529 11 місяців тому

    Hi Kevin, do you have a link to this test, thanks.

  • @youhan96
    @youhan96 10 місяців тому

    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.

  • @nomadshiba
    @nomadshiba 6 місяців тому

    why not make the parent ".scroll-reveal" itself "inline"?
    and make the children also inline.
    and use to seperate h2 and p
    i was able to do it like that without magic numbering

  • @SuperGirl-s9c
    @SuperGirl-s9c 3 місяці тому

    Hi there! Trying to figure out how to manually insert this code into a Squarespace website. Is there something I can just copy and insert?

  • @allenz0rzer
    @allenz0rzer 9 місяців тому

    Is there any way to do it "word by word" like the original website with CSS only?

  • @ilyesbenhammadi5485
    @ilyesbenhammadi5485 11 місяців тому

    Hi kevin, love your tutorials ! Can you do it with the color and text content changing when hovering ?

    • @KevinPowell
      @KevinPowell  11 місяців тому +1

      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.

  • @StevenDavisPhoto
    @StevenDavisPhoto 11 місяців тому

    On the original example, it did a word at a time. I'm wondering how they accomplished that. I prefer your outcome though.

    • @TeianDown
      @TeianDown 11 місяців тому +1

      It looks like each word is wrapped in its own . As the user scrolls, javascript adds a class to the spans, one-by-one, which changes the color of their contents from gray to white.

    • @StevenDavisPhoto
      @StevenDavisPhoto 11 місяців тому

      @@TeianDown ah it's not pure css then

  • @mohammadamaan9410
    @mohammadamaan9410 10 місяців тому

    Amazing

  • @leonardorick2404
    @leonardorick2404 2 місяці тому

    Hey! Thanks for the amazing content. Would it be possible to create the same effect with a text that has some words with different colors? Sorry repeating the comment, I commented on the wrong account before and couldn't find it to delete it. Thanks again!

  • @gE0013
    @gE0013 10 місяців тому

    Mmmmh, I'm not conviced this time, for a simple reason: as soon as you change the viewport size, you lose the timing effect. Basically, your code works just with those specific viewport sizes and for that specific text. Nevertheless, it's a brilliant solution for a very tricky problem, and has many potential uses.

  • @aboodlikesit
    @aboodlikesit 10 місяців тому

    can i control background video with css scroll?

  • @Micsc
    @Micsc 11 місяців тому

    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(