Jump to content

Incrementing Javascript

Recommended Posts

Site URL: https://www.brianspoem.com

Hello!

I currently have a script running in the sidebar that counts the number of poems. It works, but the only problem is that I have to increment it manually. I asked a programmer friend if he could help me with a script that would count the number of poems from a starting date so that I would not have to manually edit the script each day. Below is the code he sent me. Unfortunately, I can't get this script to run and he is not able to help me. This script is very much like the script currently running, so I'm not sure what the problem is. Any insight or suggestions are greatly appreciated.

🙂 Brian

===================SCRIPT BELOW===================

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

  var oTop = $('#counter').offset().top - window.innerHeight;
  if (a == 0 && $(window).scrollTop() > oTop) {
    $('.counter-value').each(function() {
      var $this = $(this),
        startDate = getDaysSinceStartDate($this.attr('data-startdate'));
      $({
        countNum: $this.text()
      }).animate({
          countNum: startDate
        },
        {
          duration: 2000,
          easing: 'swing',
          step: function() {
            $this.text(Math.floor(this.countNum));
          },
          complete: function() {
            $this.text(this.countNum);
          }
        });
    });
    a = 1;
  }
function getDaysSinceStartDate(startDate) {
   var today = new Date().getTime() / 1000;
   startDate = Date.parse(startDate) / 1000;
   return Math.floor((today - startDate) / 60 / 60 / 24);
});
</script>

<div id="counter">
<div class="sqs-col sqs-col-4 counter-value" data-startdate="07/22/2016" data-desc="Poems
Published">0</div>
</div>

Edited by Digital-Alphabet
Link to comment
  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.