我无法弄清楚这段代码有什么问题。Firefox 的错误控制台告诉我:“ this.animateImgSlider 不是函数”。
我想要的是调用this.selectImage()
,jsItems[0].selectImage(0)
然后this.animateImgSlider()
被调用多次,直到selfCall
为假:
function WindowItem(inId) {
this.id = inId;
this.imgSliderTarget = 0;
this.imgSlider = document.getElementById("imgSlider"+inId);
this.animateImgSlider = function() {
var selfCall = true;
var currLeft = parseInt(this.imgSlider.style.left, 10);
if (currLeft < this.imgSliderTarget) {
currLeft += 8;
if (currLeft >= this.imgSliderTarget) {
currLeft = this.imgSliderTarget;
selfCall = false;
}
}
else {
currLeft -= 8;
if (currLeft <= this.imgSliderTarget) {
currLeft = this.imgSliderTarget;
selfCall = false;
}
}
this.imgSlider.style.left = currLeft+"px";
if (selfCall) setTimeout("this.animateImgSlider()", 0);
}
this.selectImage = function(inImg) {
this.imgSliderTarget = -inImg*488;
this.animateImgSlider();
}
}
var jsItems = new Array();
jsItems.push(new WindowItem(0));
这一行是引发错误的行:
if (selfCall) setTimeout("this.animateImgSlider()", 0);