I need help :) I tried to find the solution in other topics, but was not able to, so I am sorry beforehand if there is any. I am a newbie.
So, the problem. I have a bunch of div's. I need to add "active" class for each div, then remove it in 2 sec, one by one.
I have the solution, but my master says that "from" and then "of" are not good at all. Any ideas how it can be done in other way? Thank you in advance!
const boxes = document.querySelectorAll('.box')
const innerBoxes = Array.from(boxes);
const clickOnDiv = fromEvent(innerBoxes, 'click')
.pipe(
map(event => {
let notActiveElements = [];
for ( let i=0; i < innerBoxes.length; i++) {
if(innerBoxes[i] != event.target) {
notActiveElements.push(innerBoxes[i])
}
}
return notActiveElements
}),
concatMap(element => from(element)
.pipe(
concatMap(element => of(element)
.pipe(
tap(el => console.log(el)),
delay(2000)
)),
tap(item => {
item.classList.add('active')
}),
delay(2000),
tap(item => {
item.classList.remove('active')
})
))
)
clickOnDiv.subscribe()