0
カウンタを使用して複数の他のショートを短くする方法を見つけましたが、自分の状況に関連するものは何も見つかりませんでした。カウンターを増やす場合に複数を短くする方法
現在、増加するカウンタごとにif文が多すぎます。
これを達成する方法はありますか?事前にみんなで
$(".gift").each(function(){
var i = 1;
$(this).on("click", function(){
if(i===1){
TweenMax.fromTo(this, 1, {x:-1}, {x:1, ease:RoughEase.ease.config({strength:8, points:5, template:Linear.easeNone, randomize:false}) , clearProps:"x"})
}
if(i===2){
TweenMax.fromTo(this, 0.9, {x:-1}, {x:1, ease:RoughEase.ease.config({strength:8, points:5, template:Linear.easeNone, randomize:false}) , clearProps:"x"})
}
if(i===3){
TweenMax.fromTo(this, 2/i, {x:-1}, {x:1, ease:RoughEase.ease.config({strength:8, points:5, template:Linear.easeNone, randomize:false}) , clearProps:"x"})
}
if(i===4){
TweenMax.fromTo(this, 2/i, {x:-1}, {x:1, ease:RoughEase.ease.config({strength:8, points:5, template:Linear.easeNone, randomize:false}) , clearProps:"x"})
}
if(i===5){
TweenMax.fromTo(this, 2/i, {x:-1}, {x:1, ease:RoughEase.ease.config({strength:8, points:5, template:Linear.easeNone, randomize:false}) , clearProps:"x"})
}
if(i===6){
TweenMax.fromTo(this, 2/i, {x:-1}, {x:1, ease:RoughEase.ease.config({strength:8, points:5, template:Linear.easeNone, randomize:false}) , clearProps:"x"})
}
if(i===7){
TweenMax.fromTo(this, 2/i, {x:-1}, {x:1, ease:RoughEase.ease.config({strength:8, points:5, template:Linear.easeNone, randomize:false}) , clearProps:"x"})
}
if(i===8){
TweenMax.fromTo(this, 2/i, {x:-1}, {x:1, ease:RoughEase.ease.config({strength:8, points:5, template:Linear.easeNone, randomize:false}) , clearProps:"x"})
}
if(i===9){
TweenMax.fromTo(this, 2/i, {x:-1}, {x:1, ease:RoughEase.ease.config({strength:8, points:5, template:Linear.easeNone, randomize:false}) , clearProps:"x"})
}
if(i===10){
$this = $(this);
TweenMax.fromTo(this, 2/i, {x:-1}, {x:1, ease:RoughEase.ease.config({strength:8, points:5, template:Linear.easeNone, randomize:false}) , clearProps:"x", onComplete:function(){
$this.css("top", "500px");
$(".gift").each(function(){
$(this).off("click");
});
}})
}
i++;
console.log(i);
});
});
ありがとう:
以下は私のコードです!
うーん...私= 3からI = 9全て同じに、私ができるよう見て、それを一つの条件に入れますか? – sinisake
'i'が' 3'以上のあらゆる状況がまったく同じであるとすれば、どうしてなぜ '' if''/'else if' /' 'else''(https://developer.mozilla.org)を使用していないのですか? /en-US/docs/Web/JavaScript/Reference/Statements/if...else)structure? 'if(i === 1){...} else if(i === 2){...} else if(i> 2){...}'? –
こんにちはsinasake、私は1行で私は= 3~私は= 9のためにそれを行うには? – Dr3am3rz