Published unlisted
Edited
Sep 6, 2022
Insert cell
# Dynamic delay in d3.interval
Insert cell
<div class='text1'>one</div>
<div class='text2'>two</div>
<div class='text3'>three</div>
<div class='text4'>four</div>
Insert cell
{
const masterSelection = d3.selectAll('[class^="text"]');
const node = masterSelection.nodes();
const len = node.length - 1;
let counter = 0;
const del = 1000;
const delay = [0, 1000, 2000, 3000];

/*
let ticker = d3.interval((e) => {
const element = masterSelection["_groups"][0][counter];
const selection = d3.select(element).node();
console.log(selection);
counter++;
counter > len ? ticker.stop() : null;
}, del);
*/
function show() {
const element = masterSelection["_groups"][0][counter];
const selection = d3.select(element).node();
console.log(selection);

counter++;
if (counter > len) return;
d3.timeout(show, delay[counter]);
}

show();
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more