I want to a typewriter effect in HTML/JavaScript/jQuery, for example this one, but I need to specify the duration total of the animation. For example if I set 10 seconds and the string is "dog" the animation will be very slow. Is this possible? Thanks.
Asked
Active
Viewed 112 times
2 Answers
1
You could modify that existing plugin to add a new function that accepts a param for totalDelay
, and then uses the existing typeString
function with delay
= totalDelay / str.length
.

Luke
- 18,811
- 16
- 99
- 115
1
I'm gonna use the same functions as in this one.
It's really simple.
On line typeString($tar, settings.text[idx], 0, settings.delay, function () {
and on line deleteString($tar, settings.delay, function () {
change settings.delay
for (settings.delay / settings.text[idx].length)
then when calling the construction function pass the delay (in ms) option with the time you want. e.g:
$('#target').teletype({
delay: 10000,
text: [
'dog',
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr,',
'sed diam nonumy eirmod tempor invidunt ut labore et dolore',
'magna aliquyam erat, sed diam voluptua. At vero eos et',
'accusam et justo duo dolores et ea rebum. Stet clita kasd',
'gubergren, no sea takimata sanctus est Lorem ipsum dolor sit',
'amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,',
'sed diam nonumy eirmod tempor invidunt ut labore et dolore',
'magna aliquyam erat, sed diam voluptua. At vero eos et accusam',
'et justo duo dolores et ea rebum. Stet clita kasd gubergren,',
'no sea takimata sanctus est Lorem ipsum dolor sit amet.'
]
});`

Community
- 1
- 1

ygorazevedo
- 487
- 1
- 4
- 14