我正在尝试将spin.js的启动延迟半秒,但是当然希望我的主代码继续在后台运行。我以为我可以通过setTimeout()轻松实现。但是似乎我的setTimeout()甚至在运行主代码(我的4秒计数器)之前就不会启动。我无休止地尝试着将函数放入函数中,试图使这个看似简单的概念起作用,但没有成功。有人可以帮忙吗? http://jsfiddle.net/yh69bvx7/
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.0.1/spin.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.0.1/jquery.spin.js"></script>
<div id="spinner"></div>
<button id="showSpinner">Show Spinner</button>
。
$.fn.spin.presets.SpinSettings = {
lines: 13,
length: 14,
width: 4,
radius: 25,
corners: 1.0,
rotate: 0,
trail: 60,
speed: 1.0,
direction: 1,
delay: 2000
};
$('#showSpinner').click(function() {
setTimeout(function() {
$('#spinner').spin('SpinSettings');
}, 500);
var count = 0;
for (var i = 0; i < 2400000000; i++) {
/* this will take approx. 4 secs */
}
console.log("done " + i + " iterations");
});