css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="cdt_wrapper">
  <div class="cdt">
    <span class="cdt_txt" id="cdt_txt"></span>
    <span class="cdt_date" id="cdt_date"></span>
  </div>
</div>
            
          
!
            
              html {
  box-sizing: border-box;
  font-size: 62.5%;
}

@media screen and (min-width: 768px) {
  html {
    font-size: 78.195%;
  }
}

body {
  font-size: 1.2rem;
  line-height: 1.75em;
}

.cdt_wrapper {
  background-color: #e9e9eb;
  font-weight: bold;
  text-align: center;
  line-height: 2;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-pack: center;
  justify-content: center;
  -ms-flex-align: center;
  align-items: center;
}

@media screen and (min-width: 768px) {
  .cdt_wrapper {
    line-height: 2.5;
    font-size: 1.8rem;
    padding: 0 20px;
  }
}

.cdt_wrapper small {
  font-size: .6em;
  padding: 0 .4em;
}

.cdt {
  display: -ms-flexbox;
  display: flex;
  -ms-flex-align: center;
  align-items: center;
  -ms-flex-pack: center;
  justify-content: center;
}

.cdt_txt {
  font-size: .6em;
  display: inline-block;
  margin-right: .6em;
}

@media screen and (min-width: 768px) {
  .cdt_txt {
    font-size: .5em;
  }
}

.cdt_txt span {
  display: block;
  line-height: 1;
}

.cdt_date {
  font-size: 1.6rem;
}

.cdt_num {
  background-color: #ffffff;
  /* font-size: 18px; */
  padding: 0 .15em;
}

@media screen and (min-width: 768px) {
  .cdt_num {
    line-height: 1;
    padding: .3em .15em;
  }
}
            
          
!
            
              function CountdownTimer(elm, tl, mes) {
  this.initialize.apply(this, arguments);
}
CountdownTimer.prototype = {
  initialize: function (elm, tl, mes) {
    this.elem = document.getElementById(elm);
    this.tl = tl;
    this.mes = mes;
  },
  countDown: function () {
    var timer = '';
    var today = new Date();
    var hour = Math.floor(((this.tl - today) % (24 * 60 * 60 * 1000 * 24 * 24)) / (60 * 60 * 1000));
    var min = Math.floor(((this.tl - today) % (24 * 60 * 60 * 1000)) / (60 * 1000)) % 60;
    var sec = Math.floor(((this.tl - today) % (24 * 60 * 60 * 1000)) / 1000) % 60 % 60;
    var milli = Math.floor(((this.tl - today) % (24 * 60 * 60 * 1000)) / 10) % 100;
    var me = this;

    if ((this.tl - today) > 0) {
      if (hour) timer += '<span class="cdt_num">' + hour + '</span><small>時間</small>';
      timer += '<span class="cdt_num">' + this.addZero(min) + '</span><small>分</small><span class="cdt_num">' +
        this.addZero(
          sec) + '</span><small>秒</small><span class="cdt_num">' + this.addZero(milli) + '</span>';
      this.elem.innerHTML = timer;
      tid = setTimeout(function () {
        me.countDown();
      }, 10);
    } else {
      this.elem.innerHTML = this.mes;
      return;
    }
  },
  addZero: function (num) {
    return ('0' + num).slice(-2);
  }
}

// ▼ 開始日時と終了日時を入力
function CDT() {

  var today = new Date();
  var myD = today.getTime(); // 1970/1/1午前0時から現在までのミリ秒
  var start = new Date('2018/11/5/ 0:00:00'); // 開始日時を入力
  var myS = start.getTime(); // 1970/1/1午前0時からの開始日時までのミリ秒
  var end = new Date('2019/11/5/ 23:59:59'); // 終了日時を入力
  var myE = end.getTime(); // 1970/1/1午前0時から終了日時までのミリ秒

  // 開始までor終了までor終了後のカウントダウンタイマー前テキスト
  if (myS <= myD && myE >= myD) {
    var text = '<span>終了</span><span>まで</span>';
    var tl = new Date(end);
  } // 終了まで
  else if (myS > myD) {
    var text = '<span>開催</span><span>まで</span>';
    var tl = new Date(start);
  } // 開始まで
  else {
    var text = '';
  } // 終了後

  var timer = new CountdownTimer('cdt_date', tl, '<small>終了しました。</small>');
  timer.countDown();
  target = document.getElementById("cdt_txt");
  target.innerHTML = text;
}

window.onload = function () {
  CDT();
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console