How to add Counter on multiple text
up vote
0
down vote
favorite
I have a multiple Pie chart that has text inside it to show the percentage and I want to animate it. below code increment, the count until the number reaches to hundred.
var text = document.querySelectorAll('text');
var duration = setInterval(count, 14);
var c = 0;
function count(){
for (var i = 0; i < text.length; i++) {
if(c == 101){
clearInterval(time);
}else {
text[i].textContent = c + '%';
}
}
c++;
}
but i want to have different text/number on each item. i tried below code but the number jumps from 0 to the value that i specified.
var text = document.querySelectorAll('text');
var duration = setInterval(count, 14);
var c = 0;
function count(){
for (var i = 0; i < text.length; i++) {
if(c == 82){
text[0].textContent = c + '%';
}else if(c == 46){
text[1].textContent = c + '%';
}else if(c == 76){
text[2].textContent = c + '%';
}else if(c == 56){
text[3].textContent = c + '%';
}else if(c == 26){
text[4].textContent = c + '%';
}else if(c == 96){
text[5].textContent = c + '%';
}
}
c++;
}
setInterval(count, 14);
javascript html timer counter
add a comment |
up vote
0
down vote
favorite
I have a multiple Pie chart that has text inside it to show the percentage and I want to animate it. below code increment, the count until the number reaches to hundred.
var text = document.querySelectorAll('text');
var duration = setInterval(count, 14);
var c = 0;
function count(){
for (var i = 0; i < text.length; i++) {
if(c == 101){
clearInterval(time);
}else {
text[i].textContent = c + '%';
}
}
c++;
}
but i want to have different text/number on each item. i tried below code but the number jumps from 0 to the value that i specified.
var text = document.querySelectorAll('text');
var duration = setInterval(count, 14);
var c = 0;
function count(){
for (var i = 0; i < text.length; i++) {
if(c == 82){
text[0].textContent = c + '%';
}else if(c == 46){
text[1].textContent = c + '%';
}else if(c == 76){
text[2].textContent = c + '%';
}else if(c == 56){
text[3].textContent = c + '%';
}else if(c == 26){
text[4].textContent = c + '%';
}else if(c == 96){
text[5].textContent = c + '%';
}
}
c++;
}
setInterval(count, 14);
javascript html timer counter
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a multiple Pie chart that has text inside it to show the percentage and I want to animate it. below code increment, the count until the number reaches to hundred.
var text = document.querySelectorAll('text');
var duration = setInterval(count, 14);
var c = 0;
function count(){
for (var i = 0; i < text.length; i++) {
if(c == 101){
clearInterval(time);
}else {
text[i].textContent = c + '%';
}
}
c++;
}
but i want to have different text/number on each item. i tried below code but the number jumps from 0 to the value that i specified.
var text = document.querySelectorAll('text');
var duration = setInterval(count, 14);
var c = 0;
function count(){
for (var i = 0; i < text.length; i++) {
if(c == 82){
text[0].textContent = c + '%';
}else if(c == 46){
text[1].textContent = c + '%';
}else if(c == 76){
text[2].textContent = c + '%';
}else if(c == 56){
text[3].textContent = c + '%';
}else if(c == 26){
text[4].textContent = c + '%';
}else if(c == 96){
text[5].textContent = c + '%';
}
}
c++;
}
setInterval(count, 14);
javascript html timer counter
I have a multiple Pie chart that has text inside it to show the percentage and I want to animate it. below code increment, the count until the number reaches to hundred.
var text = document.querySelectorAll('text');
var duration = setInterval(count, 14);
var c = 0;
function count(){
for (var i = 0; i < text.length; i++) {
if(c == 101){
clearInterval(time);
}else {
text[i].textContent = c + '%';
}
}
c++;
}
but i want to have different text/number on each item. i tried below code but the number jumps from 0 to the value that i specified.
var text = document.querySelectorAll('text');
var duration = setInterval(count, 14);
var c = 0;
function count(){
for (var i = 0; i < text.length; i++) {
if(c == 82){
text[0].textContent = c + '%';
}else if(c == 46){
text[1].textContent = c + '%';
}else if(c == 76){
text[2].textContent = c + '%';
}else if(c == 56){
text[3].textContent = c + '%';
}else if(c == 26){
text[4].textContent = c + '%';
}else if(c == 96){
text[5].textContent = c + '%';
}
}
c++;
}
setInterval(count, 14);
javascript html timer counter
javascript html timer counter
asked Nov 21 at 21:33
Kinan Alamdar
468
468
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You dont need for statement as you are accessing all elements manually and you want numbers to change while their value is smaller than target:
function count(){
if(c <= 82)
text[0].textContent = c + '%';
if(c <= 46)
text[1].textContent = c + '%';
if(c <= 76)
text[2].textContent = c + '%';
if(c <= 56)
text[3].textContent = c + '%';
if(c <= 26)
text[4].textContent = c + '%';
//after reaching to highest number you need to stop the clock
if(c <= 96)
text[5].textContent = c + '%'
else
clearInterval(time);
c++;
}
Sven Liivak. thank brother it works. i'm actually new in programming and your advice about for loop was really helpful.
– Kinan Alamdar
Nov 21 at 22:40
Now and in the future in SO: instead of "thanks" "wow" etc. comments use upvote and "accept answer" options.
– Sven Liivak
Nov 22 at 7:38
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You dont need for statement as you are accessing all elements manually and you want numbers to change while their value is smaller than target:
function count(){
if(c <= 82)
text[0].textContent = c + '%';
if(c <= 46)
text[1].textContent = c + '%';
if(c <= 76)
text[2].textContent = c + '%';
if(c <= 56)
text[3].textContent = c + '%';
if(c <= 26)
text[4].textContent = c + '%';
//after reaching to highest number you need to stop the clock
if(c <= 96)
text[5].textContent = c + '%'
else
clearInterval(time);
c++;
}
Sven Liivak. thank brother it works. i'm actually new in programming and your advice about for loop was really helpful.
– Kinan Alamdar
Nov 21 at 22:40
Now and in the future in SO: instead of "thanks" "wow" etc. comments use upvote and "accept answer" options.
– Sven Liivak
Nov 22 at 7:38
add a comment |
up vote
1
down vote
accepted
You dont need for statement as you are accessing all elements manually and you want numbers to change while their value is smaller than target:
function count(){
if(c <= 82)
text[0].textContent = c + '%';
if(c <= 46)
text[1].textContent = c + '%';
if(c <= 76)
text[2].textContent = c + '%';
if(c <= 56)
text[3].textContent = c + '%';
if(c <= 26)
text[4].textContent = c + '%';
//after reaching to highest number you need to stop the clock
if(c <= 96)
text[5].textContent = c + '%'
else
clearInterval(time);
c++;
}
Sven Liivak. thank brother it works. i'm actually new in programming and your advice about for loop was really helpful.
– Kinan Alamdar
Nov 21 at 22:40
Now and in the future in SO: instead of "thanks" "wow" etc. comments use upvote and "accept answer" options.
– Sven Liivak
Nov 22 at 7:38
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You dont need for statement as you are accessing all elements manually and you want numbers to change while their value is smaller than target:
function count(){
if(c <= 82)
text[0].textContent = c + '%';
if(c <= 46)
text[1].textContent = c + '%';
if(c <= 76)
text[2].textContent = c + '%';
if(c <= 56)
text[3].textContent = c + '%';
if(c <= 26)
text[4].textContent = c + '%';
//after reaching to highest number you need to stop the clock
if(c <= 96)
text[5].textContent = c + '%'
else
clearInterval(time);
c++;
}
You dont need for statement as you are accessing all elements manually and you want numbers to change while their value is smaller than target:
function count(){
if(c <= 82)
text[0].textContent = c + '%';
if(c <= 46)
text[1].textContent = c + '%';
if(c <= 76)
text[2].textContent = c + '%';
if(c <= 56)
text[3].textContent = c + '%';
if(c <= 26)
text[4].textContent = c + '%';
//after reaching to highest number you need to stop the clock
if(c <= 96)
text[5].textContent = c + '%'
else
clearInterval(time);
c++;
}
answered Nov 21 at 22:20
Sven Liivak
76718
76718
Sven Liivak. thank brother it works. i'm actually new in programming and your advice about for loop was really helpful.
– Kinan Alamdar
Nov 21 at 22:40
Now and in the future in SO: instead of "thanks" "wow" etc. comments use upvote and "accept answer" options.
– Sven Liivak
Nov 22 at 7:38
add a comment |
Sven Liivak. thank brother it works. i'm actually new in programming and your advice about for loop was really helpful.
– Kinan Alamdar
Nov 21 at 22:40
Now and in the future in SO: instead of "thanks" "wow" etc. comments use upvote and "accept answer" options.
– Sven Liivak
Nov 22 at 7:38
Sven Liivak. thank brother it works. i'm actually new in programming and your advice about for loop was really helpful.
– Kinan Alamdar
Nov 21 at 22:40
Sven Liivak. thank brother it works. i'm actually new in programming and your advice about for loop was really helpful.
– Kinan Alamdar
Nov 21 at 22:40
Now and in the future in SO: instead of "thanks" "wow" etc. comments use upvote and "accept answer" options.
– Sven Liivak
Nov 22 at 7:38
Now and in the future in SO: instead of "thanks" "wow" etc. comments use upvote and "accept answer" options.
– Sven Liivak
Nov 22 at 7:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420755%2fhow-to-add-counter-on-multiple-text%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown