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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <body>
  <ul>
    <li id="hours-first">
      <div class="bar">
        <div class="top"></div>
        <div class="middle"></div>
        <div class="bottom"></div>
        <div class="left-top"></div>
        <div class="left-bottom"></div>
        <div class="right-top"></div>
        <div class="right-bottom"></div>
      </div>
    </li>
    <li id="hours-second">
      <div class="bar">
        <div class="top"></div>
        <div class="middle"></div>
        <div class="bottom"></div>
        <div class="left-top"></div>
        <div class="left-bottom"></div>
        <div class="right-top"></div>
        <div class="right-bottom"></div>
      </div>
    </li>
    <li class="colon">
      <div class="colon-top"></div>
      <div class="colon-bottom"></div>
    </li>
    <li id="minutes-first">
      <div class="bar">
        <div class="top"></div>
        <div class="middle"></div>
        <div class="bottom"></div>
        <div class="left-top"></div>
        <div class="left-bottom"></div>
        <div class="right-top"></div>
        <div class="right-bottom"></div>
      </div>
    </li>
    <li id="minutes-second">
      <div class="bar">
        <div class="top"></div>
        <div class="middle"></div>
        <div class="bottom"></div>
        <div class="left-top"></div>
        <div class="left-bottom"></div>
        <div class="right-top"></div>
        <div class="right-bottom"></div>
      </div>
    </li>  
  </ul>
  <div class="confirm">
    <div class="check">確認のための時間表示</div>
    <div class="time"></div>
  </div>
</body>
              
            
!

CSS

              
                body {
  background-color: #fefefe;
  font-size: 20px;
  color: #808080;
}

ul {
  margin: 30px auto;
  padding: 0;
  width: 320px;
  height: 110px;
  display: flex;
  list-style: none;
  justify-content: space-around;
  transform: skewX(-5deg);
}

li {
  width: 18%;
  height: 100%;
}

.bar {
  position: relative;
  width: 100%;
  height: 100%;
}

.top,
.middle,
.bottom,
.left-top,
.left-bottom,
.right-top,
.right-bottom {
  position: absolute;
  display: none;
  background-color: #808080;
  transition: all 0.5s ease-in-out;
}

.top,
.middle,
.bottom {
  left: 7%;
  width: 86%;
  height: 10px;
  clip-path: polygon(12.5% 0, 87.5% 0, 100% 50%, 87.5% 100%, 12.5% 100%, 0% 50%);
}

.left-top,
.left-bottom,
.right-top,
.right-bottom {
  height: 45%;
  width: 10px;
  clip-path: polygon(50% 0, 100% 10%, 100% 90%, 50% 100%, 0 90%, 0 10%);
}

.top {
  top: 0;
}

.middle {
  top: calc(50% - 5px);
}

.bottom {
  bottom: 0;
}

.left-top {
  top: 5%;
  left: -2.5%;
}

.left-bottom {
  bottom: 5%;
  left: -2.5%;
}

.right-top {
  top: 5%;
  right: -2.5%;
}

.right-bottom {
  bottom: 5%;
  right: -2.5%;
}

.zero .bar div:not(.middle) {
  display: block;
}

.one .bar .right-top,
.one .bar .right-bottom {
  display: block;
}

.two .bar .top,
.two .bar .middle,
.two .bar .bottom,
.two .bar .left-bottom,
.two .bar .right-top {
  display: block;
}

.three .bar .top,
.three .bar .middle,
.three .bar .bottom,
.three .bar .right-top,
.three .bar .right-bottom {
  display: block;
}

.four .bar .middle,
.four .bar .left-top,
.four .bar .right-top,
.four .bar .right-bottom {
  display: block;
}

.five .bar .top,
.five .bar .middle,
.five .bar .bottom,
.five .bar .left-top,
.five .bar .right-bottom {
  display: block;
}

.six .bar div:not(.right-top) {
  display: block;
}

.seven .bar .top,
.seven .bar .right-top,
.seven .bar .right-bottom {
  display: block;
}

.eight .bar div {
  display: block;
}

.nine .bar div:not(.left-bottom) {
  display: block;
}

.colon {
  width: 5%;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
}

.colon-top,
.colon-bottom {
  width: 8px;
  height: 8px;
  border-radius: 3px;
  background-color: #808080;
}

.confirm {
  width: 320px;
  margin: 0 auto;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}

.time {
  width: 30%;
}

.check {
  width: 70%;
}
              
            
!

JS

              
                const time = () => {
  
  // 2桁表記(8:10 を 08:10 とするための関数)
  const doubleNum = function(num) {
    num += "";
    if (num.length === 1) {
      num = "0" + num;
    }
   return num;     
  };

  const now = new Date();
  const h = doubleNum(now.getHours());
  const m = doubleNum(now.getMinutes());
  
  const h1 = (h).slice(0,1);
  const h2= (h).slice(-1);
  const m1 = (m).slice(0,1);
  const m2= (m).slice(-1);
  
  // デジタル表示と実際の時間確認のため表示
  $('.time').text( h1 + h2 + ':' + m1 + m2 ); 

  const h1elem = $('#hours-first');
  const h2elem = $('#hours-second');
  const m1elem = $('#minutes-first');
  const m2elem = $('#minutes-second');

  // 時間の各数値と対応するクラスの組合わせの配列を作成
  const obj = [
    { time: h1, elem: h1elem },
    { time: h2, elem: h2elem },
    { time: m1, elem: m1elem },
    { time: m2, elem: m2elem },
  ];

  // クラスを付与する関数を作成
  function add (time, elem) {
    elem.removeClass();
    if (time == 1) {
      elem.addClass('one');
    } else if (time == 2) {
      elem.addClass('two');
    } else if (time == 3) {
      elem.addClass('three');
    } else if (time == 4) {
      elem.addClass('four');
    } else if (time == 5) {
      elem.addClass('five');
    } else if (time == 6) {
      elem.addClass('six');
    } else if (time == 7) {
      elem.addClass('seven');
    } else if (time == 8) {
      elem.addClass('eight');
    } else if (time == 9) {
      elem.addClass('nine');
    } else {
      elem.addClass('zero');
    }
  }
  
  // 先に作成した配列の各オブジェクト対して関数を実行
  $.each(obj, function(index, val) {
    add(val.time, val.elem);
  });
    
};
time();

//最初に時刻表示した後は、1分後に表示を変更する
const timeUpdate = () => {
  time();
  setTimeout(timeUpdate, 60000);
};

timeUpdate();
              
            
!
999px

Console