Search code examples
javascriptjquerycanvastimerhtml5-canvas

How to load canvas array after specific time?


My coding skills aren't the best, so I need some help with a current issue of mine.

var canvas;
jQuery(document).ready(function(){
    canvas = jQuery('#myCanvas').canvaDots({
        sizeDependConnections: false,
        randomBounceSides: false,
        dotsColor:[0,0,0,0],
        linesColor:[255,255,255],
        mouseReaction: true,
        magnetPowerDelimiter: 5,
        speed: 1.2
    });

    canvas.loadSpecificArray(1, arrayZ);
    canvas.setSpecificArray(1, function(){});
    canvas.setSpecificArrayOffsetX(10);
});

I need the following lines to get executed after a 3 second delay

canvas.loadSpecificArray(1, arrayZ);
canvas.setSpecificArray(1, function(){});

and the following after a 10 second delay.

canvas.destroytSpecificArrays(arrayZ)

How do I get this done, could you point me to a direction?


Solution

  • There's a native JS method called setTimeout that you can leverage.

    setTimeout(function() {
        canvas.destroytSpecificArrays(arrayZ)
    }, 10000) //10000 ms = 10 seconds
    

    Hopefully that works