0

Всем привет! Есть функция, которая заполняет ячейки элементами массива:

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];

(function addInCell() {
    var cell = document.getElementsByTagName('input');

    for (var i = 0; i <= cell.length; i++) {
       cell[i].value = arr[i];
    }
})();

Подскажите, пожалуйста, как осуществить заполнение ячеек не сразу, а пошагово - 1, задержка, 2, задержка и т.д.? Т.е., как бы анимированное заполнение.

1 ответ 1

1

window.onload = function() {
  var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];

  (function addInCell() {
    var cell = document.getElementsByTagName('input');

    for (var i = 0; i < cell.length; i++) {
      var s = function(i) {
        setTimeout(function() {
          cell[i].value = arr[i];
        }, 1000 * i)
      }
      s(i);
    }
  })();
}
<input type="text" name="" id="">
<input type="text" name="" id="">
<input type="text" name="" id="">
<input type="text" name="" id="">
<input type="text" name="" id="">
<input type="text" name="" id="">

3

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.