W
W
wiyod2017-10-14 00:26:57
JavaScript
wiyod, 2017-10-14 00:26:57

How to make a timeout with the assignment of classes in turn in an array of elements?

An array of three elements. Initially, all elements is-hidden
must be assigned a class in turn with the delay is-activeand loop it forever.
How to write a loop that iterates over this array? Why doesn't it work?

for(i = 0; i < this.elements.length; i++) {
      setTimeout(function() {
        this.elements[i].active = !this.elements[i].active
        this.elements[i].hidden = !this.elements[i].hidden
      }, 2500)
    }

https://codepen.io/kodej/pen/GMXxxR

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2017-10-14
@wiyod

So ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question