我想将此动画(http://aishek.github.io/jquery-animateNumber/ 示例3 )添加到我的代码中,但似乎无法正常工作。
JSFiddle代码动画:https://jsfiddle.net/252jxsjq/6/ 没有代码动画的JSFiddle:https://jsfiddle.net/252jxsjq/5/
没有动画的代码:
var counter = localStorage.getItem('rans') || 0;
var counter = Number(localStorage.getItem('rans')) || 0;
var counter1 = Number(localStorage.getItem('bans')) || 0;
$('.redanswer').click(function(){
localStorage.setItem('rans', ++counter);
$( '.bpercent' ).html( counter1 * 100 / (counter1+counter) + "%" );
$( '.rpercent' ).html( counter * 100 / (counter1+counter) + "%" );
});
var counter1 = localStorage.getItem('bans') || 0;
var counter = Number(localStorage.getItem('rans')) || 0;
var counter1 = Number(localStorage.getItem('bans')) || 0;
$('.blueanswer').click(function(){
localStorage.setItem('bans', ++counter1);
$( '.rpercent' ).text( counter * 100 / (counter1+counter) + "%" );
$( '.bpercent' ).text( counter1 * 100 / (counter1+counter) + "%" );
});
要添加的动画示例:
<p>Fun level <span id="fun-level" style="color: red;">0 %</span>.</p>
var percent_number_step = $.animateNumber.numberStepFactories.append(' %')
$('#fun-level').animateNumber(
{
number: 100,
color: 'green',
'font-size': '30px',
easing: 'easeInQuad',
numberStep: percent_number_step
},
15000
);