我在我的網站上有一個很酷的櫃檯。它基本上以一定的速率計數到一定數量。我希望它能夠達到7.2,但它只會達到7,可能是因爲它被「。」弄糊塗了。代碼如下。對於像 這樣的時間段,不確定任何奇特的代碼。謝謝!如何在<span>中放置.2?
<div class="col_one_fourth nobottommargin center col_last" data-animate="bounceIn" data-delay="600">
<i class="i-plain i-xlarge divcenter nobottommargin icon-phone"></i>
<div class="counter counter-lined"><span data-from="60" data-to="7.2" data-refresh-interval="30" data-speed="2700"></span></div>
<h5>BILLION DEVICES! On Earth!</h5>
Java腳本
counter: function(){
if(!$().appear) {
console.log('counter: Appear not Defined.');
return true;
}
if(!$().countTo) {
console.log('counter: countTo not Defined.');
return true;
}
var $counterEl = $('.counter:not(.counter-instant)');
if($counterEl.length > 0){
$counterEl.each(function(){
var element = $(this);
var counterElementComma = $(this).find('span').attr('data-comma');
if(!counterElementComma) { counterElementComma = false; } else { counterElementComma = true; }
if($body.hasClass('device-lg') || $body.hasClass('device-md')){
element.appear(function(){
SEMICOLON.widget.runCounter(element, counterElementComma);
if(element.parents('.common-height')) {
SEMICOLON.initialize.maxHeight();
}
},{accX: 0, accY: -120},'easeInCubic');
} else {
SEMICOLON.widget.runCounter(element, counterElementComma);
}
});
}
},
runCounter: function(counterElement,counterElementComma){
if(counterElementComma == true) {
counterElement.find('span').countTo({
formatter: function (value, options) {
value = value.toFixed(options.decimals);
value = value.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return value;
}
});
} else {
counterElement.find('span').countTo();
}
},
我相信會有一些JavaScript與此相伴隨。 – fubar
它是否轉換爲'int'並且您需要將其指定爲'float'? –
data-to應該處理得很好,其代碼中的其他內容會導致問題。再放一些代碼,以便我們檢查。 – Icewine