jquery
アニメーション機能を使用して、CPUで処理されているジョブをシミュレートしています。私はdivs
をid = jobj
で動的に作成し、j
は各繰り返しでジョブ番号にします。その後、div
要素をループ内の各プロセスの変数$process = $(#'job' + j)
に割り当てます。私が望むのは、ジョブが1秒間隔で1つずつキューに入ることです。すばやく連続して待ち行列に入っていますが、それはあたかもアニメーションに基づいた3つのジョブのように思えます。アニメーションのforループ内で遅延を設定する
これはこれまで私が行ってきたことです。
// Wait queue
// While jobs are using CPU, other jobs are coming in
for (j = i; j < json_process.length; j++){
// Check if CPU is being used
// Processes will be added to the input queue
// First we check if the queue is empty
if (json_process[j].waitTime != 0){
// Convert strings to numbers in the array for calculation and comparison
completedCPUTime = parseFloat(json_process[i].completedCPUTime); // update CPU time
joiningInputQueueTime = parseFloat(json_process[j].joiningInputQueueTime); // update joining queue time
// Send animation[i] to input queue if it has to wait:
if(completedCPUTime > joiningInputQueueTime && waitIndex < j){
// Create job Div element
elm = '<div id="job' + j + '" ' +
'style="background-color:red; width:5px; height:50px; position:absolute; margin-top:30px;" >' +
' </div>';
$(elm).appendTo('#animate');
// Get process div
var $process = $('#job' + j);
var pos = process.offset().left; // position of process
// The end of the queue
var queueEnd = queue.offset().left + queue.outerWidth() - process.outerWidth();
input_queue.push(j); // push job in input queue
alljobs.push(j);
// Animate Div element $process
// Pausing loop on each job going into queue
setTimeout(function() {
// Send Job joiningInputQueueTime[j] to queue div
$process.stop().animate(
{left: queueEnd},
{duration: 1000});
}, 5000);
//This will keep track of the last index waiting
waitIndexCurrent = j;
}// End of animation condition
}// End of wait condition
} // End of wait queue time For Loop
あなたの記事を更新して作成することができますコードスニペットまたはjsfiddleを使用して、実行/テストできる最新のコードを表示しますか? –
OKは – Jam1
を実行するか、これらのGoogle検索結果を最初に読み、テストしてみることができますか?https://www.google.com.ph/# q = javascript + delay –