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

Callback execution at the end of loop #12

Closed
GeoffNeal opened this issue Jun 22, 2016 · 2 comments
Closed

Callback execution at the end of loop #12

GeoffNeal opened this issue Jun 22, 2016 · 2 comments

Comments

@GeoffNeal
Copy link

I have some code:

'use strict';

var words = ["developer", "designer", "problem solver", "hard worker", "nice guy!"];
var index = 0;

$("#about h3").typeIt({
strings: "I’m Geoff and I’m a " + words[index],
startDelay: 1500,
speed: 100,
loop: true,
autoStart: false,
callback: function() {
index++;
}
});

I'm trying to write a sentence that has a different word in it each time it's written. The problem is that the callback function doesn't execute if the loop option is set to true, so it just re-writes the same sentence over and over. I've tested it and it seems that when the loop option is set to false the callback works fine.

Is there a better way of achieving this effect?

@alexmacarthur
Copy link
Owner

Hi, Geoff --

Sorry for the troubles you're having with this. The callback only executes if the loop option is set to false, since it was only designed to execute after all of the strings have been finally typed. I may consider releasing a patch to have that execute after each set of strings, though.

Additionally, when re-looping over the strings, TypeIt won't look at the strings option again; it will just re-use what's already been cached. So, to get your effect going, I'd construct the strings before passing them into TypeIt, like this:

var words = ["developer", "designer", "problem solver", "hard worker", "nice guy!"];
var sentences = [];

for(var i = 0; i < words.length; i++) {
    sentences.push('I&rsquo;m Geoff and I&rsquo;m a ' + words[i]);
}

$("#about h3").typeIt({
strings: sentences,
startDelay: 1500,
speed: 100,
loop: true,
autoStart: false
});

This will type out all of those strings, and because loop is set to true, delete the entire set (unless breakLines = false) and retype them.

I hope this helps! Let me know if you have more questions.

Alex

@GeoffNeal
Copy link
Author

Hi Alex

Thanks for the response.

Yeah that should do the trick, I'll keep an eye out for your patch if you do one though.

Geoff

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