Syntax Video
Can We Recreate this Lando Norris text effect?
Transcript
You may have seen this incredible site from Lando Norris. Wes did a breakdown of this site. If you haven't seen it, go give it a watch. Either way, we saw this really neat hover effect on these footer links and these links throughout the site, and we wanted to see how we could recreate [music] it. So, CJ, Wes, and I sat down to take a stab at it using any means possible. Guys, are you ready?
Let's do it. Ready to rock. All right. So, we're working with just the base styles here. We got the font loaded. Um, okay. So, I'm going to approach this with just uh straight up HTML because I'm an HTML guy. We're going to wrap each of these in a span. My thoughts here are we need to first wrap each letter in a span [music] and then we need to somehow duplicate the text of that span and then we'll work on some CSS [music] animation. So, first we will write a function. I think I do want to use JavaScript for this because my thought is we can like iterate over the characters and then each one has a slight animation because if if you look at what's happening here, the letters animate from the bottom up and they're staggered and then when you hover off it goes in the same order. So the first letter animates down and the last letter animates down as the last letter. And my thought also is we're basically going to replicate the text on top of itself to where it animates up,
animates down, but it has a container that is hiding the elements that animate up. I like to call this function a sparan wrap where you take some text and wrap it in a a span [music] um that takes in an element. Now, I think that these guys are going to use a [music] split on the thing. And the problem with split is that not every character [music] works with split. specifically emojis. Like if you split like black Santa, you get two things, right? So I want to use the intl segment API. Do I want to use I was thinking I was going to just like use Vue.js for this. Let's let's code until we need a framework. So I'm going to create a wrapper container.
We'll just call this link container. Yeah, I think I am going to use a framework because I think I want a span for like every single letter. Segmentor segment element.ext text content and let's just console log out the letters. What we'll do here is we'll say const else is equal to query selector all the links and for each one we'll sparan wrap it. I'm going to show something really [music] neat. I'm going to do a text shadow to accomplish the duplicate version of this. [music] I don't think these guys would expect that. So, we have the link container and then we have an element that's going to be the bottom one and then we have another element that is the top one. And we're basically going to animate between these two, but the parent container uh is going to be overflow hidden. [music] So, right now we can see both of these, but basically I want it to have a fixed height so it only shows one of these.
So, it could have like Tik Tok A and Tik Tok B. If we give it a fixed height of the font size, so it's a font size of 30 pixels. We could also set a line height of 1. And then I think if we give this a fixed height of 30 pixels with overflow hidden, we should only see the top one.
Yes, there we go. We got all of our segments. Um, in order to convert a segment to an array, use array from. Let's just wrap that whole thing in an array from. Beautiful. Okay, so now we got each of the letters for that. And let me just show you real quick. If I were to add another one with a family of many people, the family is one character. And if I were to split that instead, you'll see that it actually splits the family into mom, dad, kid, kid, and then these are zero width joiners. So we're going to be using the segment API. And then what I need to do is when we hover, first one animates up and then the second one animates from below. So my idea there is link container top and link container bottom.
We can target both of these. Uh we're going to set cursor to pointer. So the user knows that they can they can click on it. Let's just try targeting that. So we'll say when top is hovered, it should have a margin of -30 pixels.
Okay. Now I want to duplicate these. And in one of the last episodes, Scott used box reflect. And I've been wanting to use that. So webkit box reflect below. That didn't work. Okay. See how it's moving up like that?
It's going kind of infinite. It's going fast, but it should be going a little bit less fast than that. And it shouldn't be infinite. It should be a stick. Was it forwards? I believe it's forwards where it goes and then stays there. Okay. We can make this a little bit faster like this. Bingo. Bango. Yeah. So, that's the issue is when you hover it, it like comes right back because it's not it's not there anymore.
What if we said when we're hovering the link container then the top element should have a margin of -30 pixels. Yeah, something like that. And also we'll set cursor pointer on the link container itself. Now what we're going to do is add an overflow hidden to the parent.
And now it kind of works, right? Okay. So what we need to tune is we need to tune the amount it's going up and we need to tune the distance on that box shadow. So the box shadow or the text shadow could be 35 pixels just so it's off. Boom. Look at that folks. And you see every time you go over it because it finishes forward, it just works. Look at that.
Just look at that. Oh, these guys don't know what they're getting into. Non-standard. Who cares? Let's put it on the link. Yes. Oh, it's literally upside down. I don't want that. I just want a duplicate of it. Shoot. I don't think this is going to work. And I think what we want to do is we'll set bottom to -30 pixels. Yeah. So [laughter] it like overlaps with itself. But this is the point where we would like animate each one. We'd say that the animation hyphen delay is going to be a calc. But it's not going to be any sort of var. We're going to use the [music] new CSS property of I believe it's sibling index. Sibling index. It's a function.
Wes used this in another video, but it since has more support. I wonder if he remembers using this. That would be very funny if he did not. [music] These guys don't even know that I just finished this already. See Scott dancing over there. [laughter] I guess he's figured something out. We're going to have to duplicate these elements. So, what we're going to do is we're going to go to this span here and we'll give that a class of a letter. And then inside of that we'll have a span with a class of top class [music] of bottom. Good. Now the letter is [music] going to be position relative and then the span inside of that is going to [music] be position absolute.
My my thought though is so if we want it to always be the exact size, we could just have one element that is hidden. So that way it takes up the exact right amount of width. That way we don't have to have a fixed width and a fixed height. Is this going to work? Okay, co-pilot, can you do something for me instead of like in uh you know what I'm trying to say here? Okay, there [music] we go. Thank you, co-pilot, for doing something. There we go. Finished.
No, no, no, no, no. The span, the bottom span is going to be absolute. We still need to take it up. There we go. And then top zero left zero. Good. And so we don't want position fixed. We want position absolute. So that way it's relative to the parent. And so we have the container, but yeah, the container doesn't have any width and height. So we actually do need that that top element.
This top element is going to be called hidden. [music] And then that gives it the right width and height. And then we have top here. And then bottom right now, which is right above it. So, we actually want bottom to be at a top of 30 pixels instead of - 30 pixels.
We'll say the y value is zero. And then when the letter is [music] hovered, we're going to make the y value 100%. And then [music] we will simply transform the y value. Now, if I wanted to tune this up even a little bit more um and make it absolutely killer perfect, theirs are way tighter. It's way faster.
Um so I want to make this like.3 [music] seconds. Save. And the distance is too far is really what it is. Yeah. So when you hover it becomes B. And so like by default bottom is below it. And so now we can transition uh that over like 1 second. So now when we hover, look at that. Nice. So [laughter] this is the exact effect we want.
Beautiful. But now it's just a matter of of animating the individual characters instead of animating the whole thing. Now each one needs a delay every single letter. I could use CSS. What's that new feature? There's a new feature in CSS where you can increment every single time. Last time I used that in the spinny one, everybody told me I was cheating. So, we're simply just going to [music] use nth child here and put a transition delay on each of them.
Will that work? All right, let's [music] change this box shadow around. I'm turning into CSS battles with pixel pushing now. Okay, let's change this [music] translate to be 90%. [music] Guys, I finished this. Last thing we need here on a div [music] is we just need a style of display flex flex [music] direction column 20 pixels.
And we're back in action, folks. Why is the transition delay not working? Oh, cuz I'm so stupid. It's transition dash delay, not transition delay. Okay, good, good, good, good. And we're pretty much just going to have to duplicate these over and over. By the way, like I said, this is is being fixed. This is a new thing in CSS. If I have time, I will swap it over and show you the new APIs, but [music] not doing that right now. So, I think I am going to bring in Vue.js just so it'll be a bit easier to replicate all of these with different text instead of having to copy paste and like creating a bunch of spans. The nice thing about Vue.js, you can just add a CDN link.
What we should be able to do just add a link to view and then start adding some interactivity here. So we can add our script tag. We'll do this. We already have a div of ID app. So below that below the body below this style here we'll add a script tag nine. We just you just have to put enough that [music] will cover them right. And three four hopefully AI will help me out here. So this will be three.
Boom. All right, that's very slow, but at least it's working. And now for items, uh, we just have an array of all of the links. So we have, uh, Tik Tok, Instagram, YouTube, Twitch. Okay, so with that, it's automatically going to repeat them on the page. We're mounting it on the element with ID app. Oh, it has a class of app. We'll also give this an ID of app.
Illegal unknown in wrapper. [music] Is it the anchor tag? Can I not do an each inside of the anchor tag? What am I doing wrong? This effect does like call it I don't know. I finished a while ago. [laughter] There we go. And so now we automatically have that effect for all of these. And it's really just a matter of doing it once and then it gets repeated multiple times. That's literally the only reason I'm using Vue right now is I just don't I won't have to replicate a bunch of HTML.
That's way too slow. So [music] maybe it needs to be 0.02 seconds. Three, four, five, 6, [music] 7, 8, 9, 10. Yes. Okay, that's maybe too fast. Okay, now let's put those other ones back in. And then we'll go to our link in overflow hidden on it. Baby, baby, this is looking good. That now works in the same way, but each letter is it in its own container. So, we can kind of have the same animation, but uh delay it slightly. Now, let's get rid of that red background color. It's going to [music] be start looking a lot closer.
Nice. Okay. Now, it's just a matter of animating each individual [music] uh character. Um we do have to change the color of the text. So, when we are hovering, just say color red.
Okay. Um [music] we'll put a transition color. It's a little bit too long. And then [music] we'll do let's do kind of a cooler color. Color pick this. Grab something like that. There we go. That looks good. Beautiful.
I I loved how I bragged about how easy I could do this in spelt and it's like the CSS version was like absolutely no challenge at all. Now I'm curious. Theirs is faster. Mine's too slow. And what about their easing? [music] Yeah, it's e easing out. We already got that. This is three, three, five, four.
Oh man, thank goodness for AI. This stuff used to suck. I don't know the syntax. We're going to have to look up the syntax for key frames. So, we've got from and two. Uh, no. We'll call this move up B because B needs to go from 30 pixels to 0 pixels. And then move up A needs to go from 0 pixels to -30 pixels. CSS count. Oh, siblings. No, sibling index. So if I change these, get rid of all of that.
What we can do here is put a transition delay of calc sibling index times 0 decimal 0 1 second. Does this going to work? Get rid of all of this code. And now it doesn't matter how many elements are there, right? Like I could do like a bazillion things here.
And it still works. Yeah. And I think what we also need to do is this top left. All of these should be anchor tags. And we can remove the inner anchor tag. I think that's that's the first thing we should do. This is so [music] good. We are we are the best. Is that all it takes? I think I'm done folks.
Each span we don't need to change the top. We we actually we could just use a translate instead of a top and left. We can use a translate which will just keep it exactly where it is. If you really want folks to make this more configurable, we can spend time doing that as well. So like let's say if we were to bump up the font size to something like 45 pixels, it largely falls apart, right? That's because the height of here line height one will help. Um, the text shadow is going to be obviously if we do text shadow 100%, we turn off overflow hidden. Yeah, you can text shadow 100%. I don't even know if you can do that. Uh, what is a CSS character height [music] unit? EX. The character height unit is EX. So, EX.
Is that actually accurate? I want to be more clear. Move up bottom. Move up top. Okay. For each of these letters, we'll give it a class of top letter. I guess we'll give each of these a class of bottom letter. And then we can set the animation to be uh move up top. We'll do 0.25.
We'll do 1 second linear. I guess we'll figure out the easing function after. And this will be move up bottom. Same thing. But now we'll do this instead of this and see if it works in the same way. No, not at all. That's looking awesome. All right, I think I'm going to call it, guys. I win. I'm the best at this stuff. CJ probably has like what, six megabytes of JavaScript installed by now. Scott is probably writing like a document for his AI. And and here I am writing 26 lines of CSS.
Let's see if let's see if this works now. Oh, come on. Now it even works if you change the font size. Oh. Oh, child. Now, I think I'm also overthinking this because I think I can do all of the styles in line. So, the container moves, but the individual letters need to stay exactly where they are. Let's try this for the top letter.
Basically, I just want to see using transform, can I get the second ones to appear above it? Can you do translate Y on a span? This is in the Y ais, right? So, yeah, let's get rid of the absolute positioning on top and bottom. And then these anchors are just going to be display block. Might as well make it accessible as well. [music] element area label. There we go. Now you inspect element on this. There we go. So now each of my links have an area label on them. And that way by mckucking with the by this putting all this garbage inside of here, it's it's fine. It will still read aloud properly to screen readers. But now if these bottom letters have a trans translate on them, will they appear in the right spot? They don't. H does not matter what font it is. It works with JavaScript. It works with
just CSS. What other fonts? Georgia. Georgia. They're inline elements. Ah, okay. So if I set uh the letters to be uh inline block, can I translate them or transform them? Yes, that's the trick. That's the absolute trick. Okay, [laughter] so for both uh top letters and bottom letters, they need to be inline block.
And so by default, the bottom ones are not visible. But then when we hover over the link container, we need to animate them in. I'm building now UI to be able to show why mine is superior. [music] That's how far ahead I am. I'm going to build a whole website. Oh, Scott's ready. I've been ready for forever.
And then we just add a transition delay to each character based on the index. So transition delay, let's say of like 0.5 sec, uh 0.1 [music] second, but we're going to add that dynamically with an inline style. All right. So now you can see not only works with one font, we can change the font with a drop down.
Scott's adding fun stuff. Now I want to add fun stuff. Here we can set the transition delay to be just a template string of 0.1 times the index because it'll be longer for the further out the letter is. And that is all we need. And then unexpected identifier s because the s needs to be inside the template string. We'll get we're getting there. It's just a syntax issue. Okay. Moment of truth. Check this out.
[laughter] [gasps] That's it. Okay. Oh yeah. Can [music] we change the width when we hover? The overall duration we're setting to 1 second. Um, let's try it as half a second. And then we'll reduce our delay by half as well. So 0.05.
Oh, it did work. So initial value 50. Yeah, that's cool. I think we've done it. This is so cool. Okay, so if we compare when you hover, they go up. You hover out, they go down.
Oh, CJ got it. Oh, allow me to wake up. Mine even works with [ __ ] Georgia. [laughter] What other fonts can I add in here? [gasps] Wingdings. They do work. Mine even works with Wingings. Check it out. Are you ready? Yes. Oh, yeah. There we go.
Any critiques, baby? Can you change the font size? Yeah, let's try. Um, I think I only have it in two spots. the the height of the container and then also the font size itself. So if I put it in a variable, I could. But let's go. Oh, you have to change the height of his element. Yeah, but if you set it to the same size, it'll still work. No, it won't because now my translate Y is off, too.
[laughter] So yeah. Yeah, it there'd be some tweaking if I want to be able to change the change the font size, but basically it's just a bunch of spans. So I have a parent container and then it has a fixed height. So that way the bottom one is hidden by default. So it's basically outside of the clip area. And then each one of these there's a span for each of the letters that has a transition delay.
And so when you hover over the container that does a translate Y to move the ones that were below up. And then when you're when you move it out, it moves them back down. I used V.JS, but I didn't install anything. I just pulled it in from a CDN. And the main reason I used it was so I wouldn't have to have a bunch of HTML. So this basically gets repeated for every word. And then I just have an array with all the words in it. At this point, we could add anything to the list and it'll just work. I just put it in a variable and now I can change the size here and everything uses that variable.
So there we go. Beautiful. Yeah. All right. So here's mine. I added this effect after the fact just cuz I had so much time. I wrote a little bit of JavaScript which takes the text content, splits it up with the segmentor API. So if you have ever tried to split an emoji, you'll notice that they're more than one characters. So you should never use split. You should always use the incler with a granularity of letter.
And then I simply wrapped each one in a span. And then I use the first letter to define how big the element will be. And then the second letter is going to be absolutely positioned on top. So I did not have to explicitly set a width or height on each letter. I also to put the delay on each of them. I used and last time I used this everyone said I cheated but it is now in most browsers. The you can use a sibling index. So the delay is simply how many it's in multiplied by 0.01 second. And that way I could have an element that is many many lines long.
Right. And it will still it'll [laughter] still work. Right. Nice. Let's see if this works here that I can change the speed and see if the speed Oh. So now you can change the speed. So not only can you change the speed, it not only works with any font size. There's also a you can also have the variable font do an effect and it still works.
Not only that, [music] uh you can change the font. Oh my goodness. You can have it be comic sand. Oh, comic sands. I didn't type correctly. You can have it be wingdings and it still works. [laughter] Uh Georgia still works. Nice. The interesting aspects of this are that I used text shadow for the duplicate version. So I don't duplicate any DOM.
I'm just using text shadow. Uh there's some other really neat things here. This thing being fully variable because I use the EX unit. So the [music] text is being pushed down by 2 EX, which is the X height of the character. And [music] then when I'm animating it up, all I'm doing is animating it up by uh this should be 2x. Um it's being animated by 2x up or down. So that's why it's it doesn't have to be any pixel values hardcoded. Um, it's just animating that up or down.
But why couldn't you just do it 100%. In [music] CSS? Yeah. Well, let me tell you, I did. Oh, and the only difference here is that I did use sibling index instead of setting it as a variable. That's the only difference. It still just works 100% the same way.
Wait, so you did no JavaScript in this version? No JavaScript. Yeah. Uh, can I see your HTML, though? Do you have a bunch of spans in your HTML? Yeah. Yeah, of course. He added the spans himself. What a loser. That's how you do it. But in real world, you would just do a little each like there. Bingo. Bingo.
Yeah, it's true, man. Scott, wait. Go over top. I I can see the the the bottom the top of your M, Scott. Yeah, that's a future thing. Who cares? Look how [laughter] smooth this looks. Awesome, guys. Holy cow, that was a lot of fun. I really enjoyed this one. Yeah. Uh, it was fun to be able to do it in Spa, too, to see like just how much easier JavaScript makes our lives sometimes, but also really only just needed for the markup, honestly. [music] Yeah, same. All right, down in the comments below, who did the best
Quote it with credit and a link. Quoting Syntax