所以我被困在這個腳本,並且無法弄清楚如何完成它。我需要它在完成其動畫之後將new_string更改爲舊字符串,然後在012或64分鐘後用setInterval
將新舊字符串中的相同動畫運行到我將從JSON中抓取的新字符串。下面是該腳本:卡在數字和字母隨機化javascript
$(document).ready(function() {
var old_string = "first word";
var new_string = "second word";
while (old_string.length < new_string.length) {
old_string += " ";
}
while (new_string.length < old_string.length) {
new_string += " ";
}
for (i = 0; i < 18; i++) {
var cell_id = create_cell();
cycle_characters(old_string.charCodeAt(i), new_string.charCodeAt(i), cell_id);
}
});
var create_cell = function() {
var $rack = $("#rack");
var cell_id = "cell_" + $("#rack .cell").size() + 1;
$rack.append($("<span class='cell first_run'>").attr("id", cell_id));
return cell_id;
}
var cycle_characters = function (old, newer, cell_id) {
// 32 = space; 126 = tilde
// low-range ASCII only
var lower_limit = 32;
var upper_limit = 126;
var old = parseInt(old);
var newer = parseInt(newer);
if (old > upper_limit || old < lower_limit) {
old = lower_limit;
}
if (newer > upper_limit || newer < lower_limit) {
newer = lower_limit;
}
if ("string" != typeof cell_id) {
cell_id = $(cell_id).attr("id");
}
var $cell = $("#" + cell_id);
$cell.text(String.fromCharCode(old));
if (newer != old) {
var call = "cycle_characters(" + (old + 1) + ", " + newer + ", " + cell_id + ")";
if ($cell.hasClass("first_run")) {
$cell.removeClass("first_run");
setTimeout(call, 1000);
} else {
setTimeout(call, 20);
}
}
}
這裏也是一個JsFiddle
對不起,我想幫助,但你的解釋是沒有幫助。你希望它做什麼,它現在沒有正確執行(基於小提琴)? – sberry 2013-03-23 00:40:49
我需要這個在Setinterval上運行,並且new_string不斷被設置爲默認值,然後在Setinterval發生後,它會將相同的動畫運行到一個來自JSON的新值。 – Keleko 2013-03-23 00:46:23