我想用动画数出一个数字。我有一个HTML代码,我设置了数字和一个计算这个数字的函数。问题是我有一个数字95%
后面有一个百分号字符。但是这个函数删除了这个字符。你有什么想法为什么?用动画计算数字
var fired = 0;
$(document).ready(function() {
\t if(fired === 0) {
\t \t $('.count').each(function() {
\t \t \t $(this).prop('Counter',0).animate({
\t \t \t \t Counter: $(this).text()
\t \t \t \t }, {
\t \t \t \t duration: 3000,
\t \t \t \t easing: 'swing',
\t \t \t \t step: function (now) {
\t \t \t \t $(this).text(Math.ceil(now));
\t \t \t \t }
\t \t \t });
\t \t });
\t \t fired = 1; //Only do scroll function once
\t }
});
.count {
font-size: 50px;
margin-bottom: 10px;
font-weight: 900;
text-transform: uppercase;
display: block;
padding-top: 15px;
}
#counter {
float: left;
display: block;
width: 28.71111111%;
text-align: center;
padding: 0 30px;
}
#counter h3 {
font-size: 1.2em;
font-weight: 100;
text-transform: uppercase;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="counter">
\t <h3>
\t \t <span class="count customer-satisfaction">95%</span>
\t \t Customer Satisfaction
\t </h3>
</div>
仅为%符号添加一个范围。 – Aslam
@hunzaboy我尝试过,但问题是该函数删除这个百分比字符;),当我把它放在一个新的跨度跨度以外的CSS形成丢失 – ItsOdi