アニメーション中にクリックイベントをバインドしたい場合は、次のコードは成功しますが、addscore()
funcitonはそれ以上解決しませんか?クリックイベントを伴うjqueryアニメーション
function moveObstacle(target,distance){
target.removeClass('animated bounce');
target.animate({ left: distance },{
duration: 10000,
progress: function(now, fx){
$(this).addClass('animated bounce');
$(this).click(function(){
$(this).hide();
addscore();
});
}
});
}
function addscore(){
score2++;
if(score2 == 10){
score1++; score2 = 0;
}
$('.scoreNum').eq(0).html(score1);
$('.scoreNum').eq(1).html(score2);
}
進捗コールバックが起動されるたびに、新しいクリックイベントを結合している、その理由! –
アニメーション中に画像をクリックすると、スコアが追加されます。 – Fan