kay899 kay899 - 3 months ago 7
jQuery Question

How can I run two own functions with a delay?

I have written two own functions, which I will now run automatically, but with an delay of 1500 ms.

When the counter reaches 7 the

preDial()
function is called. This is working so far.

When
preDial()
is done the system should wait 1500 ms and the call the
dialSequence()
function which contains an array and should execute the
each()
with all the gives values.

So how can I call these two functions with that delay?

Here is my code so far:

var count = 0;
var IDs = [];
var red = '#CC1919';
var green = '#30944B';
var orange = '#FDCA39';

$('.glyphs').on('click', function(e) {
e.preventDefault();
count ++;
dataId = $(this).attr('data-id');
dataIcon = $(this).attr('data-icon');
IDs.push([count, dataId]);

$('#glyph-' + dataId).css('border-color', red);
$('a#glyphs-' + dataId).contents().unwrap();

if (count == 7) {
preDial();
$(this).delay(1500).dialSequence();
}
});

function preDial() {
$('.chevron-active').fadeIn('slow');
$('.chevron-active').fadeOut('slow');
$('#status').delay(750).text('Dialing . . .').css('color', orange);
$('#sg_dial_circle').delay(750).addClass('rotate_right');
}

function dialSequence(IDs) {
console.log('here');
$.each(IDs, function(index, value) {
console.log(value);
$('.chevron-active.chevron-0' + index).delay(index * 1000).fadeIn('slow');
$('.line-0' + index).delay(index * 1000).addClass('line-red');
});
}




Thanks

kay899

Answer
setTimeout(function(){ 
    dialSequence(IDs);
}, 1500);

it's better to do without jQuery, and you forgot to pass IDs to function