我试图每次增加计数器,但是当点击html时,计数器会像+1,+ 2,+ 3,+ 4一样呈指数级增长。计数器递增成倍增加
$('.dates').click(function(){
$('#output').html(function(i, val) { return val*1+1 });
});
HTML:
<div id="output">0</div>
心动画代码:
var rand = Math.floor(Math.random() * 100 + 1);
var flows = ["flowOne", "flowTwo", "flowThree"];
var colors = ["colOne", "colTwo", "colThree", "colFour", "colFive", "colSix"];
var timing = (Math.random() * (1.3 - 0.3) + 1.6).toFixed(1);
// Animate Particle
$('<div class="particle part-' + rand + ' ' + colors[Math.floor(Math.random() * 6)] + '" style="font-size:' + Math.floor(Math.random() * (30 - 22) + 22) + 'px;"><i class="fa fa-heart-o"></i><i class="fa fa-heart"></i></div>').appendTo('.particle-box').css({ animation: "" + flows[Math.floor(Math.random() * 3)] + " " + timing + "s linear" });
$('.part-' + rand).show();
// Remove Particle
setTimeout(function() {
$('.part-' + rand).remove();
}, timing * 1000 - 100);
- 为什么会成倍递增?
- 我该如何让它每次增加1?像0,1,2,3,4
你可以在JSFiddle上重现这个吗? –
post html请 –
它运作良好https://jsfiddle.net/v58dfs8u/我认为你多次绑定你的事件 –