淡入淡出轮播

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

posted @ 2019-04-18 10:44  Asaru  阅读(128)  评论(0编辑  收藏  举报