2

Firstly I would apologize for the framing of the question. I am an infant with regards to my coding skills.

I am trying to achieve a count-up sequence on my Squarespace website and so far I have gotten till here (code below). Now I am trying to setup this code in such a way that in line

<div class="sqs-col sqs-col-4 counter-value" data-count="179" data-desc="Days completed">0</div> 

Instead of manually entering a value for data count, I want to calculate the number of days passed since the date that the company started. Something similar to one found here. Once that is calculated the count-up sequence will consider that number as a data-count value.

Now I have seen various count up timer codes on the forums and on different websites, however, haven't managed to successfully integrate that with the code I have here.

Any help with this would be appreciated.

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
var a = 0;
   $(window).on('load', function() {

   var oTop = $('#counter').offset().top - window.innerHeight;
  if (a == 0 && $(window).scrollTop() > oTop) {
    $('.counter-value').each(function() {
      var $this = $(this),
        countTo = $this.attr('data-count');
      $({
        countNum: $this.text()
      }).animate({
          countNum: countTo
        },
        {
          duration: 5000,
          easing: 'swing',
          step: function() {
            $this.text(Math.floor(this.countNum));
          },
          complete: function() {
            $this.text(this.countNum);
          }
        });
    });
    a = 1;
  }
});
</script>
<div id="counter">
    <div class="sqs-col sqs-col-4 counter-value" data-count="179" data-desc="Days completed">0</div>
  <div class="sqs-col sqs-col-4 counter-value" data-count="437" data-desc="Projects Executed">0</div>
  <div class="sqs-col sqs-col-4 counter-value" data-count="31" data-desc="Satisfied Clients">0</div>
</div>


<style>
 .counter-value { 
    font-size: 60px;
   line-height:1.2em;
   text-align:center;
   padding:2px 0;
 }
  .counter-value:after {
   content: attr(data-desc);
    display:block;
    text-transform:uppercase;
    font-size: 14px;
    line-height:1.5em;
  }
</style>

1 Answers1

0

The window load function had to be changed, since there was an error in console because of this.

Error:

Uncaught TypeError: url.indexOf is not a function at jQuery.fn.init.jQuery.fn.load (VM811 jquery.js:9823) at VM326:60

JSFiddle: here

The line changed:

$(window).on('load', function() {

Reference:

  1. URL.indexOf not found
Naren Murali
  • 19,250
  • 3
  • 27
  • 54