いくつかのボタンをアニメーション化しようとしています。アニメーションボタンは常に同じシーケンスではないランダムな文字列を生成する必要があります。 fiddle要素をランダムシーケンスでアニメーション化する
例:
text = 1423
最初のアニメーションのボタンであるbtn1
次いで後1秒btn4
次いで、1秒後btn2
次いで一秒btn3
ボタン後:
<div>
<button name="btn1" type="submit" id="btn1" value="1" style="" class="button"></button>
<button name="btn2" type="submit" id="btn2" value="2" style="" class="button"></button>
</div>
<div>
<button name="btn3" type="submit" id="btn3" value="3" style="" class="button"></button>
<button name="btn4" type="submit" id="btn4" value="4" style="" class="button"></button>
</div>
javascript:
var textArray = [];
var text = "";
function makeid()
{
var possible = "1234";
for(var i=0; i < 4; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
makeid();
textArray = text.split("");
console.log(textArray);
function animate1() {
$('#btn' + textArray[0]).animate({ backgroundColor: 'red' }, 500);
}
function animate2() {
$('#btn' + textArray[1]).animate({ backgroundColor: 'red' }, 500);
}
function animate3() {
$('#btn' + textArray[2]).animate({ backgroundColor: 'red' }, 500);
}
function animate4() {
$('#btn' + textArray[3]).animate({ backgroundColor: 'red' }, 500);
}
window.setTimeout(animate1, 1000);
window.setTimeout(animate2, 2000);
window.setTimeout(animate3, 3000);
window.setTimeout(animate4, 4000);