Jump to content

Adding custom Codepen code to my website - Countdown Timer

Recommended Posts

  • Replies 1
  • Views 1.2k
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Add a Code Block >> paste this code

<div class='wrap' ng-app='app'>
  <div class='time-to'>
    The world might end in...
    <span countdown='' date='January 1, 2020 12:00:00'>&nbsp;</span>
  </div>
</div>
<style>
  .wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: black;
}

.time-to {
  text-align: center;
  font-family: Bangers;
  color: white;
  font-size: 35px;
  letter-spacing: 2px;
}
.time-to span {
  display: block;
  font-size: 80px;
  color: red;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script>
  (function() {
  angular.module('app', []).directive('countdown', [
    'Util',
    '$interval',
    function(Util,
    $interval) {
      return {
        restrict: 'A',
        scope: {
          date: '@'
        },
        link: function(scope,
    element) {
          var future;
          future = new Date(scope.date);
          $interval(function() {
            var diff;
            diff = Math.floor((future.getTime() - new Date().getTime()) / 1000);
            return element.text(Util.dhms(diff));
          },
    1000);
        }
      };
    }
  ]).factory('Util', [
    function() {
      return {
        dhms: function(t) {
          var days,
    hours,
    minutes,
    seconds;
          days = Math.floor(t / 86400);
          t -= days * 86400;
          hours = Math.floor(t / 3600) % 24;
          t -= hours * 3600;
          minutes = Math.floor(t / 60) % 60;
          t -= minutes * 60;
          seconds = t % 60;
          return [days + 'd',
    hours + 'h',
    minutes + 'm',
    seconds + 's'].join(' ');
        }
      };
    }
  ]);

}).call(this);

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiPGFub255bW91cz4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7RUFBQSxPQUFPLENBQUMsTUFBUixDQUFlLEtBQWYsRUFBc0IsRUFBdEIsQ0FFQSxDQUFDLFNBRkQsQ0FFVyxXQUZYL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yNFxuICAgICAgdCAtPSBob3VycyAqIDM2MDBcbiAgICAgIG1pbnV0ZXMgPSBNYXRoLmZsb29yKHQgLyA2MCkgJSA2MFxuICAgICAgdCAtPSBtaW51dGVzICogNjBcbiAgICAgIHNlY29uZHMgPSB0ICUgNjBcbiAgICAgIFsgZGF5cyArICdkJywgaG91cnMgKyAnaCcsIG1pbnV0ZXMgKyAnbScsIHNlY29uZHMgKyAncycgXS5qb2luICcgJ1xuICB9XG5dIl19
//# sourceURL=coffeescript
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

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.