2

Currently, this function seems to count all the way to the higher value. I want it to simply count to the lower value of 30.

This is the script:

$(".circleStatsItemBox").each(function() {
  var value = $(this).find(".value > .number").html();
  var unit = $(this).find(".value > .unit").html();
  var percent = $(this).find("input").val() / 100;

  countSpeed = 2300 * percent;
  endValue = value;

  $(this).find(".count > .unit").html(unit);
  $(this).find(".count > .number").countTo({
    from: 0,
    to: endValue,
    speed: countSpeed,
    refreshInterval: 50
  });

  //$(this).find(".count").html(value*percent + unit);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/mhuggins/jquery-countTo/master/jquery.countTo.js"></script>
<div class="circleStatsItemBox yellow">
  <div class="header">Levels of Interest</div>
  <span class="percent">% Increase</span>
  <div class="circleStat">
    <input value="25" class="whiteCircle" type="text">
  </div>
  <div class="footer"><span class="count"> 
    <span class="number">30</span>
    <span class="unit">Before</span>
    </span> <span class="sep"> / </span>
    <span class="value"> 
<span class="number">40</span>
    <span class="unit"> During</span>
    </span>
  </div>
</div>

2
  • Can you explain this ? :I want it to simply count to the lower value of 30. Commented Nov 14, 2016 at 18:47
  • sure, sorry formy terrible explaining. the class"number" in this instance is 30 so i basically want the counter to just count up to 30 .... or whatever is in that html area ... in this instance it is 30 ... the counter seems to count all the way up to the higher figure which is 40 Commented Nov 14, 2016 at 19:04

1 Answer 1

1

You need to change a selector in the JavaScript code.

var value = $(this).find(".count > .number").html();

$(".circleStatsItemBox").each(function() {
  var value = $(this).find(".count > .number").html();
  var unit = $(this).find(".value > .unit").html();
  var percent = $(this).find("input").val() / 100;

  countSpeed = 2300 * percent;
  endValue = value;

  $(this).find(".count > .unit").html(unit);
  $(this).find(".count > .number").countTo({
    from: 0,
    to: endValue,
    speed: countSpeed,
    refreshInterval: 50
  });

  //$(this).find(".count").html(value*percent + unit);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/mhuggins/jquery-countTo/master/jquery.countTo.js"></script>
<div class="circleStatsItemBox yellow">
  <div class="header">Levels of Interest</div>
  <span class="percent">% Increase</span>
  <div class="circleStat">
    <input value="25" class="whiteCircle" type="text">
  </div>
  <div class="footer">
    <span class="count"> 
      <span class="number">30</span>
      <span class="unit">Before</span>
    </span>
    <span class="sep"> / </span>
    <span class="value"> 
      <span class="number">40</span>
      <span class="unit"> During</span>
    </span>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

3 Comments

That worked although not entirely sure what was wrong there ? thanks so much for your help
the only issue with this is that it appends the larger number text and not the "before"
The ".value > .number" selector was setting the end value for the count to 40. Changing the selector to ".count > .number" set the value to 30.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.