3
I have this bar percentage and I wanted to dynamically change the value of it only I’m not getting it.
Bar code
<script>
$('.bar-percentage[data-percentage]').each(function () {
var progress = $(this);
var percentage = Math.ceil($(this).attr('data-percentage'));
$({countNum: 0}).animate({countNum: percentage}, {
duration: 2000,
easing:'linear',
step: function() {
// What todo on every count
var pct = Math.floor(this.countNum) + '%';
progress.text(pct) && progress.siblings().children().css('width',pct);
}
});
});
</script>
<div id="bar-5" class="bar-main-container">
<div class="bar-percentage" data-percentage="51"></div>
<div class="bar-container">
<div class="bar"></div>
</div>
</div>
Code I used to try to change Dynamically
<script>
$('.bar-percentage').attr('data-percentage','60')//irá receber um valor diferente depois de efectuar cálculos
</script>
Thank you very much!
– MANIAMAX
You’re welcome! I’m glad I could help.
– Samir Braga
:) I tried to integrate this into my code and does not load the black bar ;(
– MANIAMAX
@MANIAMAX, I THINK I KNOW THE PROBLEM, I WILL EDIT THE ANSWER WITH A POSSIBLE SOLUTION
– Samir Braga
ok :) appears as http://i1069.photobucket.com/albums/u479/thepeterpah/Captura%20de%20ecra%202015-12-28%20as%2015.17.41_zpspihayoh5.png
– MANIAMAX
You created some way to get the bar to load with a
onload
, am o glued the code?– Samir Braga
Add a
$(document).ready(..
, as in my reply issue.– Samir Braga
even so the platform in question does not work is developed in extj and does not accept the ready Document
– MANIAMAX
I have two questions: Does the button function work? And in the example of your code, which is in question, the first case with the
$('.bar-percentage[data-percentage]').each(
worked?– Samir Braga
Yes with the
$('.bar-percentage[data-percentage]').each(
works with the button also does not work– MANIAMAX
Try
$('.bar-percentage[data-percentage]').each( changePercentage($('.bar-percentage')))
– Samir Braga
does not work in the same but thanks for the help I will see another way and then put here the solution
– MANIAMAX
Anyway, excuse me, I took into consideration only what was in the question. But, good luck
– Samir Braga
no need to apologize was a big help :)
– MANIAMAX