JS:
function randComp() {
return Math.floor((Math.random() * compliments.length) + 1) - 1;
};
function generateCompliment() {
var rand = randComp();
return compliments[rand]
};
$('button').on('click', function() {
$('h1').html(generateCompliment());
$('h1').addClass('animated slideInLeft');
});
HTML:
<div class="content">
<h1>Compliment Generator</h1><br/>
<button class="btn btn-default">Another one!</button>
</div>
赞美只是一个字符串数组。
单击该按钮时,随机赞美从左侧滑入,然后在下一次单击时,<h1>
。只是消失了。我该如何解决这个问题?
最佳答案
在添加 css 类之前 'animated slideInLeft'
删除相同的类是存在的
$('button').on('click', function() {
$('h1').removeClass('animated slideInLeft');
$('h1').html(generateCompliment());
$('h1').addClass('animated slideInLeft');
});
希望这个工作:)
关于javascript - 如何使用 animate css 显示随机赞美?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36689431/