Я использую функцию анимации jquery
для имитации заданий, обрабатываемых в CPU. Я создаю divs
динамически с id = jobj
с 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
или вы можете попробовать сначала прочитать и проверить эти результаты Google? https://www.google.com.ph/# q = javascript + delay –