Answer the question
In order to leave comments, you need to log in
How to execute functions in a queue that contains timers and animations?
It is necessary to go through an array of functions in a loop and execute them so that each next one starts after the timers and animations of the previous one are completely completed
Unfortunately, I could not figure out this task
<button id="d1">111</button>
<button id="d2">222</button>
<button id="d3">333</button>
<script type="text/javascript">
function d1() {
$('#d1').slideUp(1000).slideDown(1000);
}
function d2() {
setTimeout(function(){
$('#d2').hide(1000).show(1000);
},2000);
}
function d3() {
$('#d3').fadeOut(1000).fadeIn(1000);
}
var arf=[d1, d2, d3];
for(var i = 0; i<arf.length; i++) {
// .....
}
</script>
Answer the question
In order to leave comments, you need to log in
maybe so?
function d1(f) {
$('#d1').slideUp(1000).slideDown(1000, f);
}
function d2(f) {
setTimeout(function(){
$('#d2').hide(1000).show(1000, f);
},2000);
}
function d3(f) {
$('#d3').fadeOut(1000).fadeIn(1000, f);
}
var arf=[d1, d2, d3];
for(var i = 0; i<arf.length; i++) {
arf[i](arf[i+1])
// .....
}
maybe so
function d1() {
$('#d1').slideUp(1000).slideDown(1000);
cb();
}
function d2() {
setTimeout(function(){
$('#d2').hide(1000).show(1000);
cb();
},2000);
}
function d3() {
$('#d3').fadeOut(1000).fadeIn(1000);
cb();
}
var fns = [ d1, d2, d3 ];
function cb()
{
var fn = fns.shift();
if( typeof fn == 'function' ) fn.call();
}
cb();
Rather Deferred.
And it is well written about him here - anton.shevchuk.name/jquery-book (from page 83)
not strong in js, but why not return some value to the function on execution, and then through
switch (returnedValue) {
//...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question