我正在使用jquery
動畫函數來模擬CPU中正在處理的作業。我使用id = jobj
動態創建divs
,其中j
是每次迭代的作業編號。之後,我將div
元素分配給循環中每個進程的變量$process = $(#'job' + j)
。我想要的是工作在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向我們展示我們可以運行/測試的最新代碼? –
好的將會這樣做 – Jam1
或者您可以嘗試先閱讀並測試這些谷歌結果?https://www.google.com.ph/# q = javascript +延遲 –