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;
}

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

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

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄