0

当用户猜错鱼的名字时,我想摇晃一张图片。我正在使用有条件的ng-class="{'shake':error}". 然而,即使答案是正确的,图像也会抖动。我不相信在任何时候$scope.error都设置为真的。我在这里想念什么?

密码笔

4

1 回答 1

0

我认为你想要做的是从你的函数中returnguessIsCorrect 或guessIsWrong 。compare

$scope.compare = function(guess) {
    guess = guess.replace(/\s/g, '').toLowerCase();
    var answers = [];
    answers.push($scope.name.replace(/\s/g, '').toLowerCase());

    currentAnimal.alts.forEach(function(alt) {
        answers.push(alt.toLowerCase().replace(/\s/g, ''));
    });
    //console.log(answers);
    //console.log("Guess: " + guess + "\n");
    //console.log("Answer: " + answers + "\n");

    for (var x = 0; x <= answers.length; x++) {
        if (guess === answers[x]) {
            return guessIsCorrect();
        }
        if (x === answers.length) {
            return guessIsWrong();
        }
    }

};
于 2017-01-15T21:06:07.647 回答