How do i add such caret in my website ?

https://monkeytype.com/ It is using event listener and moving caret on each letter type but the problem is how do i find specific width for each letter cuz all letters don' t have same width, I thought of alternative approach which is adding ::after pseudo property but doing this i will not get the caret move effect like in above website.
Monkeytype | A minimalistic, customizable typing test
The most customizable typing test website with a minimal design and a ton of features. Test yourself in various modes, track your progress and improve your speed.
No description
20 Replies
MarkBoots
MarkBootsβ€’10mo ago
in the example screenshot, they use a monospace type font. Those characters have all the same width
Bismuth
BismuthOPβ€’10mo ago
what if i wanna add functionality where user can change font type ?
Nihan
Nihanβ€’10mo ago
Each character might actually be inside its own element. I am on the phone so can't really check... And then you check the width of the element which holds a character. But the very fact that they are changing the color of each character suggests that I might be correct
Bismuth
BismuthOPβ€’10mo ago
they are using separate span tag for each letter
MarkBoots
MarkBootsβ€’10mo ago
indeed they do. so with js (getBoundingClientRect() ) you can get the size of each
Nihan
Nihanβ€’10mo ago
Nice @Bismuth Not sure what exactly you want to build but I hope it's not to just change the caret colo Color*
MarkBoots
MarkBootsβ€’10mo ago
probably the position of the caret
Nihan
Nihanβ€’10mo ago
Probably
MarkBoots
MarkBootsβ€’10mo ago
although, there might be other options. (transparent text) for what is typed, and the caret as after pseudo element attached to it. It al depend on how the project of OP is build.
Nihan
Nihanβ€’10mo ago
That's cool idea
Bismuth
BismuthOPβ€’10mo ago
im cloning same site
Nihan
Nihanβ€’10mo ago
It's open source... I will recommend reading their code
Bismuth
BismuthOPβ€’10mo ago
but after pseudo will not allow me to add smooth caret move effect that's huge code base : ) im not capable of that
Nihan
Nihanβ€’10mo ago
You only live once.. Go for it 😜
Bismuth
BismuthOPβ€’10mo ago
as of now lol
Nihan
Nihanβ€’10mo ago
Btw, I did read some of it out of boredom once.. You actually can go through some of it
Bismuth
BismuthOPβ€’10mo ago
also who reads that much when i can ask experts like you hereπŸ˜›
Nihan
Nihanβ€’10mo ago
Lol ... The bug I am trying to fix has a different opinion apparently Good luck @Bismuth
MarkBoots
MarkBootsβ€’10mo ago
yea, it is positioned absolute, so you'll have to check the last character that is added. get the position (boundingClientRect) of the character, and place the caret behind it
MarkBoots
MarkBootsβ€’10mo ago
No description
Want results from more Discord servers?
Add your server