Answer the question
In order to leave comments, you need to log in
How to make a print effect?
I want to make the effect of typing text using Vue, like here - https://github.com/mattboldt/typed.js/
But for some reason the string is built not "printed" gradually, but one at a time. How to make text change spell by letter? https://codepen.io/kodej/pen/gGERPR
Answer the question
In order to leave comments, you need to log in
Add a property that will indicate how many characters to show:
data: () => ({
showChars: 0,
...
}),
computed: {
typedString() {
return this.string.slice(0, this.showChars);
},
},
<h2>{{ typedString }}</h2>
mounted() {
const intervalID = setInterval(() => {
if (++this.showChars === this.string.length) {
clearInterval(intervalID);
}
}, 50);
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question