【发布时间】:2019-03-31 09:49:38
【问题描述】:
我已经编写了一些代码作为对象来淡入和淡出一些图像,只有当我要求构建幻灯片时,我才会得到一个
“未捕获的 ReferenceError:未定义 imgArray”。
任何人都可以帮助我了解为什么会出现此错误。谢谢。
const slideShow = {
curIndex: 0,
imgDuration: 10000,
slider: document.querySelector('.banner__slider').childNodes,
imgArray: [
'images/background/img3.jpg',
'images/background/img1.jpg',
'images/background/img2.jpg'
],
buildSlideShow(arr) {
for (i = 0; i < arr.length; i++) {
const img = document.createElement('img');
img.src = arr[i];
slider.appendChild(img);
}
},
slideShow() {
function fadeIn(e) {
e.className = "fadeIn";
};
function fadeOut(e) {
e.className = "";
};
fadeOut(slider[curIndex]);
curIndex++;
if (curIndex === slider.length) {
curIndex = 0;
}
fadeIn(slider[curIndex]);
setTimeout(function () {
slideShow();
}, imgDuration);
},
};
slideShow.buildSlideShow(imgArray).slideShow();
【问题讨论】:
标签: javascript arrays object