淡入淡出轮播

var oBox = document.getElementById("box");
var pic = document.querySelectorAll("#box>img");
var timer = null;
var iNow = 0;
var n = 0;
setInterval(function () {
  if (iNow == pic.length - 1) {
    iNow = 0;
  } else {
    iNow++;
  }
  toImg();
}, 3000)
function toImg() {
  move(pic[n], { opacity: 0 });
  move(pic[iNow], { opacity: 100 });
  n = iNow;
}

思路:n始终跟随iNow,iNow当跳转为length-1的时候,变为0

原文地址:https://www.cnblogs.com/asablog/p/10728223.html