Uncaught TypeError: Cannot read property '1' of undefined
setTimeout.elementsCollection.style.position shake.js:66
ライン66は以下のとおりです。
this.elementsCollection[ i ].style.left = parseInt(Math.random() * 20) + 'px';
そして完全なコード:
Shake.prototype.shakeEffect = function(){
if(this.elementsCollection.length != false){
var positions = this.shakePosition.split('|');
for(var i = 0; i < this.elementsCollection.length; ++i){
this.elementsCollection[ i ].style.position = 'relative';
this.effectInterval = setInterval(function(elementsCollection) {
for(var x = 0; x < positions.length; ++x){
switch(positions[ x ]){
case 'left':
this.elementsCollection[ i ].style.left = -Math.abs(Math.random() * 20) + 'px';
break;
case 'right':
this.elementsCollection[ i ].style.left = parseInt(Math.random() * 20) + 'px';
break;
case 'top':
case 'up':
this.elementsCollection[ i ].style.top = -Math.abs(Math.random() * 20) + 'px';
break;
case 'down':
this.elementsCollection[ i ].style.top = parseInt(Math.random() * 20) + 'px';
break;
}
}
} , this.getInterval());
setTimeout(function(){
return function(){
clearInterval(this.effectInterval);
this.elementsCollection[ i ].style.position = null;
}
} , this.getTimeout());
}
}
}
ありがとう!
エラーが続くが、今これです:
はので、これは動作するはずです:あなたはこれをしなければならない キャッチされない例外TypeErrorは:プロパティを読み取ることができません '1' 未定義 自己shake.jsの:66 行66: this.elementsCollection [i] .style.left = parseInt(Math.random()* 20)+ 'px'; –
は、私は物事を変えた..しかし、同じエラー –
は更新を参照してください。関数は引数として 'i'だけを取ります。 –