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

Initial value #77

Open
magnusskogen opened this issue Dec 12, 2019 · 5 comments
Open

Initial value #77

magnusskogen opened this issue Dec 12, 2019 · 5 comments
Labels

Comments

@magnusskogen
Copy link

Is it possible to have an initial value? Let's say we start off with a sentence:

I like to drink coffee.

And then the word coffee gets erased and changed to beer.

@zhouzi
Copy link
Owner

zhouzi commented Dec 13, 2019

Sure, it can be achieved by limiting TheaterJS to the word you want to change. The following should work:

<h1>I like to drink <span id="drink"></span>.</h1>
theaterJS()
	.addActor('drink')
	.addScene('drink:coffee')
	.addScene('drink:beer');

In this example, TheaterJS is only going to change the content of the span with the id "drink".

@magnusskogen
Copy link
Author

magnusskogen commented Dec 13, 2019

Thanks for your reply. However I'm not sure if this answers my question? I'd like the actor drink to have an initial value, that is erased.

This would be the starting point:

<h1>I like to drink <span id="drink">coffee</span>.</h1>

And when addScene('drink:beer') is triggered, the word coffee is erased, and beer is written.

Does that make sense? Right now it seems a word has to be programmatically added to the scene before it can be erased.

@zhouzi
Copy link
Owner

zhouzi commented Dec 15, 2019

Yes, your example should work. You can initialize the markup with the value you want it to have initially. Are you having any trouble with it?

@magnusskogen
Copy link
Author

You are right, coffee is erased. Or I'd rather say it's removed. It would be nice if it was erased backwards, letter by letter.

@zhouzi
Copy link
Owner

zhouzi commented Dec 17, 2019

Oh ok, I now understand what you're looking for 👍 I'm afraid that is not possible without playing with the library's internals.

Could you tell me more about your use case? Are you trying to use TheaterJS with a server-side rendered application? Knowing more about the use case could help me come up with the proper solution.

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

No branches or pull requests

2 participants