I am putting together a powerpoint type web page, where the slides slide in and and of view with various animations. The animation sequence is held in an array (ultimately loaded from a database), and called using eval()
When the slide is clicked, the next set of animations is actioned, but I need each one to wait until the previous one has finished. So for the code below, when the SeqNo is 1, I want the ShowSlideLeft to wait until HideSlideRight as finished.
I have looked at callbacks and promises, but I cant get them to work as I cannot hard code the chaining events.
var SeqNo;
$(document).ready(function () {
$('.slide').click(function (e) {
ActivateSequence(++SeqNo);
});
SeqNo = 0;
SetupSequence();
ActivateSequence(SeqNo);
});
function SetupSequence() {
Sequence = [];
Sequence[0] = [];
Sequence[0][0] = "ShowSlideLeft('S1');";
Sequence[1] = [];
Sequence[1][0] = "HideSlideRight('S1');";
Sequence[1][1] = "ShowSlideLeft('S2');";
}
function ActivateSequence(Seq) {
var action;
var element;
if (Seq < Sequence.length) {
for (var i = 0; i < Sequence[Seq].length; i++) {
eval(Sequence[Seq][i]);
}
}
}
function ShowSlideLeft(div) {
var showoptions = { "direction": "left", "mode": "show" };
$('#' + div).effect("slide", showoptions, 1000);
}
function ShowSlideRight(div) {
var showoptions = { "direction": "right", "mode": "show" };
$('#' + div).effect("slide", showoptions, 1000);
}
function HideSlideLeft(div) {
var showoptions = { "direction": "left", "mode": "hide" };
$('#' + div).effect("slide", showoptions, 1000);
}
function HideSlideRight(div) {
var showoptions = { "direction": "right", "mode": "hide" };
$('#' + div).effect("slide", showoptions, 1000);
}
Many thanks for any help you can give.