Search code examples
jqueryjquery-pluginsdelay

Spin.js, Using .delay() and stopping a spinner


I'm using spin.js for a spinner on a page. There is a small jquery plugin that calls the spinner and also stops it. My problem is getting the spinner to stop after a delay. The spinner won't load with my delay code to stop it. Here is my code:

$("#loaderIcon").spin({
lines: 12, // The number of lines to draw
length: 7, // The length of each line
width: 4, // The line thickness
radius: 10, // The radius of the inner circle
color: '#000', // #rgb or #rrggbb
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false // Whether to render a shadow

});
$("#loaderIcon").delay(3000).spin(false);

Any help would be appreciated!


Solution

  • delay only works for the animation queue - it does not, as it might seem to, block for the provided time. You should use setTimeout if the delay does not need to block:

    setTimeout(function(){ $("#loaderIcon").spin(false); }, 3000);