Jump to content

Incrementing Javascript

Recommended Posts

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


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>
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()
          countNum: startDate
          duration: 2000,
          easing: 'swing',
          step: function() {
          complete: function() {
    a = 1;
function getDaysSinceStartDate(startDate) {
   var today = new Date().getTime() / 1000;
   startDate = Date.parse(startDate) / 1000;
   return Math.floor((today - startDate) / 60 / 60 / 24);

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

Link to comment
  • Replies 0
  • Views 446
  • Created
  • Last Reply


This topic is now archived and is closed to further replies.

  • 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.