Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div style="text-align: right">
  <a target="_blank" class="gh" href="https://github.com/hughanderson4/angular-countdown">View project on GitHub</a>
</div>
<div ng-app="app" ng-controller="demoController as vm" style="text-align: center">
    <div class="countdown-con countdown-xs">
        <countdown countdown-id="cd1" countdown-title="Days Until Christmas" target-date="vm.xmas"></countdown>
    </div>

    <hr />

    <div class="countdown-con countdown-sm orange">
        <countdown countdown-id="cd2" countdown-title="Hours Until Tomorrow" target-date="vm.tomorrow"></countdown>
    </div>

    <hr />

    <div class="countdown-con countdown-md">
        <countdown ng-hide="vm.expired.cd3" countdown-id="cd3" countdown-title="Expiring Countdown" target-date="vm.expiring"></countdown>
        <h2 ng-show="vm.expired.cd3">Expired Countdown!</h2>
    </div>

    <hr />

    <div class="countdown-con countdown-lg orange">
        <countdown countdown-id="cd4" countdown-title="Days Until 2018" target-date="'2018-01-01'"></countdown>
    </div>
  
<script type="text/ng-template" id="/dist/countdown.html">
<div class="countdown clearfix" ng-class="vm.countdownId">
    <h2 class="text-uppercase" ng-bind="vm.countdownTitleDisplay"></h2>
    <div ng-hide="vm.hasDate">
        <h1 class="coming-soon">Coming Soon</h1>
    </div>
    <div class="countdown-row-con" ng-show="vm.hasDate">
        <div class="row row-colons">
            <div class="col-xs-4" ng-if="vm.days">
                <h1 class="well well-lg">
                    {{vm.days}}
                </h1>
                <h4>Days</h4>
            </div>
            <div class="col-xs-4">
                <h1 class="well well-lg">
                    {{vm.hours}}
                </h1>
                <h4>Hours</h4>
            </div>
            <div class="col-xs-4">
                <h1 class="well well-lg">
                    {{vm.minutes}}
                </h1>
                <h4>Mins</h4>
            </div>
            <div class="col-xs-4" ng-if="!vm.days">
                <h1 class="well well-lg">
                    {{vm.seconds}}
                </h1>
                <h4>Secs</h4>
            </div>
        </div>
    </div>
</div>
</script>
</div>

              
            
!

CSS

              
                body {
  font: 12px Arial;
  background: white;
}
a.gh {
  font-size: larger;
  font-weight: bold;
  text-decoration: none;
  background: blue;
  color: white;
  padding: 6px 14px;
  border-radius: 4px;
}

.countdown-con {
    text-align: center;
    font-size: 10px;
}
.countdown-xs {
    font-size: 9px;
}
.countdown-sm {
    font-size: 11px;
}
.countdown-md {
    font-size: 14px;
}
.countdown-lg {
    font-size: 20px;
}
.countdown .well {
    padding: 0;
    display: inline-block;
    width: 1.8em;
    line-height: 1.6em;
    border: 3px solid #54ABAE;
    box-shadow: none;
    background: white;
    margin: 3px auto;
    border-radius: 0;
}
.countdown h1 {
    font-size: 2.5em;
    font-weight: bold;
}
.countdown h2 {
    font-size: 1.6em;
    font-weight: bold;
    margin: 10px 0 5px;
}
.countdown h4 {
    font-size: 1.4em;
    font-weight: normal;
    text-transform: uppercase;
    margin: 0 0 5px;
    color: #54ABAE;
}
.countdown .row {
    white-space: nowrap;
}
.countdown .row-colons .col-xs-4:not(:last-child):after {
    content: ':';
    position: absolute;
    font-size: 4.7em;
    right: -0.17em;
    top: -0.12em;
    font-weight: normal;
    color: #54ABAE;
}
.countdown [class^="col-"] {
    float: none;
    display: inline-block;
    width: auto;
    padding: 0 8px;
    position: relative;
}
.countdown-con.orange .well {
    border-color: #FF9E15;
}
.countdown-con.orange h4 {
    color: #FF9E15;
}
.countdown-con.orange .row-colons .col-xs-4:not(:last-child):after {
    color: #FF9E15;
}
              
            
!

JS

              
                  (function() {
    angular.module('app', []);
    angular.module('app').controller('demoController', demoController);

    demoController.$inject = ['$scope']; 
    function demoController($scope) {
      var vm = this;
      vm.tomorrow = new Date();
      vm.tomorrow.setHours(24,0,0,0); // midnignt tomorrow

      vm.xmas = new Date();
      vm.xmas.setMonth(11);
      vm.xmas.setDate(25);
      vm.xmas.setHours(0,0,0,0); // midnignt
      
      vm.expired = {};
      
      vm.expiring = new Date();
      vm.expiring.setTime(vm.expiring.getTime() + 1000 * 10); // expiring in 10 seconds
      
      $scope.$on('countdown-expired', function(event, exp) {
        vm.expired[exp.name] = true;
      });
    }

    angular.module('app').controller('countdownController', countdownController);
    countdownController.$inject = ['$interval', '$scope']; 
    
    function countdownController($interval, $scope) {
      /* jshint validthis:true */
      var vm = this;
      vm.targetDate;  // targetDate is bound via the directive
      vm.countdownTitle; // title is bound via the directive
      vm.countdownId; // countdownId is bound via the directive
      vm.countdownTitleDisplay = vm.countdownTitle;

      if (vm.targetDate == '') {
        vm.targetDate = null;
      }

      vm.hasDate = !!vm.targetDate;
      if (!vm.hasDate) {
        vm.countdownTitleDisplay = vm.countdownTitle.replace("Coming In", '');
        return;
      }

      var endDate = new Date(vm.targetDate);

      vm.days;
      vm.hours;
      vm.minutes;
      vm.seconds;

      var msPerSecond = 1000;
      var msPerMinute = 60 * msPerSecond;
      var msPerHour = msPerMinute * 60;
      var msPerDay = msPerHour * 24;
      var stop;

      activate();

      function activate() {
        var timeDiff = endDate.getTime() - new Date().getTime();
        if (timeDiff <= 0) {
          vm.days = vm.hours = vm.minutes = vm.seconds = 0;
          stop && $interval.cancel(stop);
          stop = undefined;
          $scope.$emit('countdown-expired', { name: vm.countdownId });
          return;
        }

        vm.days = Math.floor(timeDiff / msPerDay);
        timeDiff -= vm.days * msPerDay;
        vm.hours = Math.floor(timeDiff / msPerHour);
        timeDiff -= vm.hours * msPerHour;
        vm.minutes = Math.floor(timeDiff / msPerMinute);
        timeDiff -= vm.minutes * msPerMinute;
        vm.seconds = Math.floor(timeDiff / msPerSecond);
      }

      stop = $interval(activate, msPerSecond);
    }
    
    angular.module('app').directive('countdown', countdown);
    countdown.$inject = [];
    
    function countdown () {
      // Usage:
      //     <countdown></countdown>
      // Creates:
      // 
      return {
        restrict: 'E',
        templateUrl: '/dist/countdown.html',
        controller: 'countdownController',
        controllerAs: 'vm',
        scope: {
          targetDate: '=',
          countdownTitle: '@',
          countdownId: '@'
        },
        bindToController: true
      };
    }
})();
              
            
!
999px

Console