JS函数需要在实例上并行运行

时间:2017-08-23 07:29:23

标签: jquery loops iterator

在此功能中,图像正确旋转。但是我需要它来为类.svg的一些实例工作。在它通过实例的那一刻。需要帮助。



$(document).ready(function() {
  var images = $('.svg > img');
  var numImages = images.length;
  var innerLoopIterator = 0;
  var outerLoopIterator = 0;
  var numOuterLoops = 20;
  var stayTime = 800;

  images.hide();

  function rotateImage() {
    images.eq(innerLoopIterator)
      .fadeIn()
      .delay(stayTime)
      .queue(function(next) {
        innerLoopIterator += 1;
        if (innerLoopIterator >= numImages) {
          innerLoopIterator = 0;
          outerLoopIterator += 1;
        }
        if (outerLoopIterator < numOuterLoops) {
          next();
          rotateImage();
        }
      })
      .fadeOut();
  }
  rotateImage();
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="svg">
  <img src="https://dummyimage.com/160x120/000/fff&text=pic+1" />
  <img src="https://dummyimage.com/160x120/000/fff&text=pic+2" />
  <img src="https://dummyimage.com/160x120/000/fff&text=pic+3" />
  <img src="https://dummyimage.com/160x120/000/fff&text=pic+4" />
  <img src="https://dummyimage.com/160x120/000/fff&text=pic+5" />
</div>
&#13;
&#13;
&#13;

0 个答案:

没有答案