Day # 21: Automatic Text
Similar to the Typewriter effect that I had posted a few days ago, there is another cool effect that we can add to display text in our websites. That effect consists of an automatic animation that displays the letters of a sentence with a certain interval.
In order to do that, we could employ the slice method in Javascript, in which we divide that sentence into single characters, which are the ones that will display with a certain frequency:
function writeText() {
text.innerText = content.slice(0, index)
text.style.fontSize = `${size}px`
index++
}Additionally, I thought it’d be cool to add the possibility to choose the size of the font of that animation, a functionality that corresponds to the second line within that writeText() function, in which we are modifying the font-size of the character in a dynamic way.
Comments
Post a Comment