2016-07-25 124 views
0

我正在使用動態增長的進度條。 進度條下方是百分比值,也是動態生成的。如何用javascript增加百分比值

$('.progress-bar').animate({ width: '100%' }, { 
    duration:2000, 
    step: function(now, fx) { 
     if (fx.prop == 'width') { 
      var newval = Math.round(now * 100)/100 + '%'; 
      $([this, $(this).nextAll('.count')[0]]).html(newval); 
     } 
    } 
}); 

這是我到目前爲止有:http://jsfiddle.net/zjdBh/34/

我怎樣才能擺脫在進度的百分比值嗎?下面的百分比應保持不變,但在進度條的textvalue應該消失

回答

2
$('.progress-bar').animate(
    {width:'100%'}, 
    { 
     duration:2000, 
     step: function(now, fx) { 
      if(fx.prop == 'width') { 
       var newval = Math.round(now * 100)/100 + '%';      
       $([$(this).nextAll('.count')[0]]).html(newval); 
      } 
     } 
    }   
); 
+0

太棒了!感謝你的回答 –

-3

使用的字體大小零值開了竅 改變你的CSS ..

.progressbar { 

inline-block; 
    font-size:0px !important; 
    text-intent:-9999999px !important; 
    color:transparent !important 
} 
+0

不是一個很好的解決方案,只是掃描地毯下的錯誤。 – James

+0

是的,我知道。 @judgeja這就是爲什麼我說的技巧 –

+2

英語在「做伎倆」和「是訣竅」之間有差異 - 「訣竅」的意思是「這是確切的,最佳實踐的解決方案」 –

2

在這裏看到jsfiddle

在線

$([this, $(this).nextAll('.count')[0]]).html(newval); 

您將html添加到this這是.progress-bar並向$(this).next('.count')

所以只要去掉第一this像這樣

$([$(this).nextAll('.count')[0]]).html(newval); 

讓我知道,如果它可以幫助

0

您需要刪除展示%年齡一部分在count div。 this是否適合你?