D
D
Denis Bukreev2016-10-31 16:13:06
JavaScript
Denis Bukreev, 2016-10-31 16:13:06

How to set a delay in a for loop?

There is a task: in an array of elements to hide in turn each element.

I select elements through for, but how to set a delay of at least 300ms between each iteration?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GreatRash, 2016-10-31
@denisbookreev

var i = 0;
var max_i = 10;
var interval = null;

interval = setInterval(function() {
  // some code
  
  i++;

  if (++i > max_i) {
    clearInterval(interval);
  }
}, 300);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question