-
Notifications
You must be signed in to change notification settings - Fork 67
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
Event Handler #10
Comments
Hello @jonsecchis 😄 Thanks, I'm glad that you liked it! Yes there is! Below are a few examples to stop, start, play, resume... Basic start / stop via var morphext = $("#js-rotating").Morphext({
animation: "rotateIn"
});
var data = morphext.data("plugin_Morphext");
// Start Morphext (autostarts by default)
data.start();
// Stop Morphext
data.stop();
// Basic example (https://github.com/MrSaints/Morphext/blob/master/index.html#L23)
$("#js-rotating").Morphext({
animation: "rotateIn",
complete: function () {
console.log("This is called after a phrase is animated in! Current phrase index: " + this.index);
}
}); // With start(), and stop() (https://github.com/MrSaints/Morphext/issues/3#issuecomment-58606183)
$("#js-rotating").Morphext({
complete: function () {
// 1. Stop if phrase index is 3
if (this.index === 3) {
this.stop();
}
// 2. Stop if phrase is "Stop here" by retrieving the current phrase through its index
if (this.phrases[this.index] === "Stop here") {
this.stop();
}
// 3. Stop at the last phrase
if (this.index === this.phrases.length - 1) {
this.stop();
}
}
}); Shuffling: Finally, with jQuery's // Fisher-Yates Shuffle (see http://bost.ocks.org/mike/shuffle/)
function shuffle(array) {
var m = array.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
// From demo file
var $morphext = $("#js-rotating").Morphext({
animation: "rotateIn",
complete: function () {
console.log("This is called after a phrase is animated in! Current phrase index: " + this.index);
}
});
// Important bit
var $data = $morphext.data("plugin_Morphext");
console.log("Before: " + $data.phrases);
shuffle($data.phrases);
console.log("After: " + $data.phrases); As mentioned in another issue, there's no specific pub/sub kind of event [emitter], and I don't think I have plans for it in the near future as most use cases are already covered without them. I hope this helps! And please do feel free to let me know if it doesn't. I'm more than happy to help you with your specific use case. |
Thank for such detailed response. I could not get it to work in the situation I am facing. I have your plugin animating in sync with a carousel in the same page. It works like this:
The problem is that when the window doesn't have focus, the animations lost sync. I can stop the carousel using the
I tried using I'm a novice in programming, but seems to me that I can't use the And my attempts to run the events from outside the plugin function didn't work at all. Here is the page in question, it is under construction: http://www.vitoriaship.com.br/v4 |
Ideally, it's best to avoid playing with the focus of the window. I'll look into why it's getting out of sync, but meanwhile, have you tried using You can access the current index with Also, the In your case, the window focus / blur event is external to the plugin (it controls both Morphext, and the Carousel). It needs to be used in something like |
Using I've tried I will test it further, but it seem like I have a solution! Thank you very much! |
No problem. I'm glad it works! 😅 I'll continue looking into the problem nevertheless. Thanks! |
Hi, great plugin!
I am just wondering, is there a way to add stop, start, play, resume events to be called outside the plugin?
Thank you!
The text was updated successfully, but these errors were encountered: