【发布时间】:2015-06-02 07:56:27
【问题描述】:
我在myClass 有这个方法。当它到达数组的末尾时,我希望它从 0 重新开始,但是现在它只是停止了。
this.jsonParse = function() {
for (var i = 0; i < this.numberOfPhotos; i++){
(function(index, selector, timing, arrayLength){
setTimeout(function() {
$(selector).css('background-color': obj_gallery.images[index].hex);
}, index*timing);
})(i, this.slideWrap, this.timing,this.numberOfPhotos);
}
}
我在下面尝试过类似的方法,但它不起作用。
if (index >= arrayLength) {
index = 0;
}
注意之前已经定义了this.numberOfPhotos等局部变量。
【问题讨论】:
-
你能做一个小提琴吗?
-
.css('background-color': obj_gallery...。该语法看起来不正确。 -
可能是个愚蠢的问题,但你试过
if (i > arrayLength) { i = 0; }吗? -
@elclanrs 我错过了关于背景颜色值的引号(对吗?),但它已经完成了......看看笔。我的问题在 cicle 上。
标签: javascript arrays for-loop settimeout