Giter Club home page Giter Club logo

Comments (6)

tameemsafi avatar tameemsafi commented on June 2, 2024

You are able to chain the deleteAll function anywhere and it will be called once it reaches that stage.

Example:
https://jsfiddle.net/2dwL47bu/

from typewriterjs.

amxmln avatar amxmln commented on June 2, 2024

Thanks for your reply, I am aware of that, the point is that it has to reach that point, i.e. the string has to be fully typed out and there's no way to cancel that and directly skip to the next step.

I was asking for a feature to clear the current event queue and start a new one, so I don’t think this issue is resolved.

Edit: to clarify further, I think the way this plugin works right now is that for every chained call, it adds an entry to a queue-array and keeps working off this queue in a first-in-first-out basis (or looping over it in case looping is enabled). What I would like to see would be a way to cancel all still remaining items in the queue, hence flushing / emptying it, and starting from scratch as if I was first instantiating the typewriter. I hope this makes it more clear.

from typewriterjs.

tameemsafi avatar tameemsafi commented on June 2, 2024

Thank you for your reply. You are correct regarding the queue system. However, there must be a point in the queue for it to call some kind of method to flush the queue. So it would not be possible to include the function you are requesting. This would essentially mean doing a check after processing each item in the queue in order to flush the queue at a certain point, which I think is incorrect for what you need.

You can achieve what you need through the current API. Use the javascript MutationObserver in order to listen for any changes in the wrapper element. Then you can check if the wrapper element meets a condition and stop the typewriter instance and re-create it again.

Example:
https://jsfiddle.net/yxLmvq8c/

from typewriterjs.

amxmln avatar amxmln commented on June 2, 2024

I only glanced over the source code, so I could be wrong here, but wouldn’t a method on the typewriter instance itself suffice? Say there’s a method flush() that stops the typewriter and flushes the queue when called externally (so not as part of a chain) and then the queue can be filled again like usual? The state the instance was in could be kept as the initial state for the new queue, i.e. if a word was currently being typed it would still stay visible up to the point it was typed and could be modified by subsequent calls.

In any case, thank you for your example, I guess I could simply replace the typewriter instance whenever I need it to restart—I’ll have to find a way to make it look less jagged though.

from typewriterjs.

tameemsafi avatar tameemsafi commented on June 2, 2024

No problem, I think re-creating the whole instance would be better than flushing the queue as this would only be required in very specific circumstances. You have full control over the object that is created, so you can choose when to re-create it. I hope that works for you, but would be happy to re-consider if it becomes a problem for other users of the plugin.

from typewriterjs.

amxmln avatar amxmln commented on June 2, 2024

Yes, I think you have a valid point there. Thanks for your help and suggestions and being open about reconsidering should it come up again! 👍

from typewriterjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.