Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop() doesn't work as expected (or not at all) #166

Open
HunterAhlquist opened this issue Dec 27, 2022 · 1 comment
Open

stop() doesn't work as expected (or not at all) #166

HunterAhlquist opened this issue Dec 27, 2022 · 1 comment

Comments

@HunterAhlquist
Copy link

HunterAhlquist commented Dec 27, 2022

Hi, I'm trying to use stop() to interrupt the typewriter effect so it can move immediately into deleteAll() which I put after stop(). However, either stop() doesn't work as expected or it's not working at all because typewriter continues to type out the rest of the text then moves into deleteAll() as if stop() was never even there.
Here's an example:

let typeWriter = new Typewriter(tabContent, {
    loop: false,
    delay: 25,
    deleteSpeed: 15,
    cursor: '',
});

function interrupt() {
    typeWriter.stop();
    typeWriter.deleteAll(15);
    typeWriter.typeString("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
}

typeWriter.typeString("123456789123456789123456789123456789123456789123456789123456789123456789123456789");
setTimeout(function() { interrupt(); }, 1000);

Is this unintended, user-error, or is the stop() explanation missing something?

@Jeandcc
Copy link

Jeandcc commented Mar 14, 2023

You need to modify the state.eventQueue after you call stop and empty the array of the queue. That did the trick for me.

You might need to manually override the TS types that coem with the package, they don't include the state pro in the TypewriterClass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants