Dionysus Dionysus - 1 year ago 65
Javascript Question

$.each display data then pause for 3 seconds

I'm iterating a JSON file using

. I want my page to show data for say 3 seconds, pause for 3 seconds then move on to the next one and repeat. I have this code:

setTimeout(function() {

I thought this would do it but this only waits for 3 seconds and then displays each bit of data in succession, and I need them to be 3 seconds apart.

How do I get that? Thanks!

Answer Source

Times by the index:-

$.getJSON(url, function(json1) {
  $.each(json1.data, function(numb) {
    setTimeout(function() {
    }, 3000 * num);

This will make the 1st 0 seconds, 2nd 3 seconds, 3rd 6 seconds, etc.

or it you want the 1st to wait also, use:

3000 * (num+1)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download