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>
  <div class="circle">
    <div class="inner">
      <div class="time one">&#8544;</div>
      <div class="time two">&#8545;</div>
      <div class="time three">&#8546;</div>
      <div class="time four">&#8547;</div>
      <div class="time five">&#8548;</div>
      <div class="time six">&#8549;</div>
      <div class="time seven">&#8550;</div>
      <div class="time eight">&#8551;</div>
      <div class="time nine">&#8552;</div>
      <div class="time ten">&#8553;</div>
      <div class="time eleven">&#8554;</div>
      <div class="time twelve">&#8555;</div>
      <div class="short"></div>
      <div class="long"></div>
    </div>
  </div>
</body>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  color: #222;
  font-size: 20px;
}

.circle {
  position: relative;
  margin: 20px auto;
  width: 255px;
  height: 255px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  border: 9px solid #898989; /* バトルシップグレイ */
  background: #f3f3f3;
  box-shadow: 4px 4px 0px #bfbfbf, 
              inset 3px 3px 0px #e6e6e6, 
              inset 2px 4px 8px #555;
  filter: drop-shadow(2px 3px 6px #777);
}

.circle::before{
  position: absolute;
  inset:0;
  content: "";
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(247,247,247,0.5) 0%,rgba(209,232,255,0.1) 20%,rgba(255,255,255,0.7) 30%,rgba(224,239,255,0.1) 50%,rgba(255,255,255,0.7) 70%,rgba(209,232,255,0.2) 80%,rgba(247,247,247,0.3) 100%);  
  z-index: 10;
}

.inner {
  position: relative;
  transform: translate(2px, 2px);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-image: linear-gradient(135deg, #b0b0b0 0%, #b5b5b5 1%, #d9d9d9 20%, #efefef 48%, #d9d9d9 75%, #bcbcbc 100%);
  box-shadow: 1px 1px 2px 1px rgba(0,0,0,0.65), inset 2px 2px 4px 0px #f3f3f3;
  transform-style: preserve-3d; /* 短針と長針をZ軸にマイナス移動 */
}

.time,
.long,
.short {
  position: absolute;
  inset: 0;
  line-height: 1.1;
  font-weight: 700;
}

.short,
.long {
  background: #808080;
  transform-origin: bottom center;
}

.short {
  top: calc(10px - 55px);
  left: calc(50% - 2px);
  width: 6px;
  height: 55px;
  transform: translateZ(-2px); /* JSで上書きされるため記述不要、位置確認のため */
}

.long {
  top: calc(10px - 80px);
  left: calc(50% - 1px);
  width: 3px;
  height: 80px;
  transform: translateZ(-3px); /* JSで上書きされるため記述不要、位置確認のため */
}

.one {
  transform: translate(50px, -86.6px); /* 水平 */
}

.two {
  transform: translate(86.6px, -50px);
}

.three {
  transform: translate(100px, 0);
}

.four {
  transform: translate(86.6px, 50px);
}

.five {
  transform: translate(50px, 86.6px);
}

.six {
  transform: translate(0px, 100px);
}

.seven {
  transform: translate(-50px, 80px);
}

.eight {
  transform: translate(-86.6px, 50px);
}

.nine {
  transform: translate(-100px, 0px);
}

.ten {
  transform: translate(-86.6px, -50px);
}

.eleven {
  transform: translate(-50px, -86.6px);
}

.twelve {
  transform: translate(0px, -100px);
}
              
            
!

JS

              
                const time = () => {  // 時刻表示の関数作成

  const now = new Date(); //現在の日時を取得
  const h = now.getHours(); //時間のみ取得
  const m = now.getMinutes(); //分のみ取得
  const short = $('.short');
  const long = $('.long');
  
  // 短針の角度
  const shortDeg = h < 13 ? h * 30 + m / 60 * 30 : (h - 12) * 30 + m / 60 * 30; //if-else文を1行にした短縮記法
  short.css('transform', 'rotate(' + shortDeg + 'deg) translateZ(-1px)');
  
  // 長針の角度
  const longDeg = m * 6;
  long.css('transform', 'rotate(' + longDeg + 'deg) translateZ(-2px)');
  
  // 短針の影の向き
  if (shortDeg < 90) {
    short.css('box-shadow', '0.7px 0px 1.5px #000'); // 回転する前の要素の右と下に影
  } else if (shortDeg < 180){
    short.css('box-shadow', '0.7px -0.7px 1.5px #000'); // 右と上に影
  } else if (shortDeg < 270){
    short.css('box-shadow', '-0.7px -0.7px 1.5px #000'); // 左と上に影
  } else {
    short.css('box-shadow', '-0.7px 0px 1.5px #000'); // 左と下に影
  }    

  // 長針の影の向き
  if (longDeg < 90) {
    long.css('box-shadow', '0.7px 0px 1.5px #000'); // 回転する前の要素の右と下に影
  } else if (longDeg < 180){
    long.css('box-shadow', '0.7px -0.7px 1.5px #000'); // 右と上に影
  } else if (longDeg < 270){
    long.css('box-shadow', '-0.7px -0.7px 1.5px #000'); // 左と上に影
  } else {
    long.css('box-shadow', '-0.7px 0px 1.5px #000'); // 左と下に影
  }    

};

time();  // 時刻表示の関数呼び出し

//最初に時刻表示した後は、1分後に表示を変更する
const timeUpdate = () => {  // 1分後に時刻表示の関数を呼び出す関数作成
  time();
  setTimeout(timeUpdate, 60000);  // 1分間隔
};

timeUpdate();
              
            
!
999px

Console