js+css实现世界各个地区时区当前时间大转盘切换效果代码

代码语言:html

所属分类:其他

代码描述:js+css实现世界各个地区时区当前时间大转盘切换效果代码,点击中间点可切换时区。

代码标签: js css 世界 各个 地区 时区 当前 时间 大转盘 切换

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
  
<style>
*,
::before,
::after {
  box-sizing: border-box;
}
:root {
  --clr-bg: rgb(3 3 3);
  --clock-size: 800px;
  --clock-clr: rgb(12, 74, 110);
}
body {
  margin: 0;
  min-height: 100svh;
  display: grid;
  place-content: center;
  font-family: system-ui;
  background-color: var(--clr-bg);
  background-image: radial-gradient(rgb(8, 47, 73),rgb(8, 47, 60));
  background-blend-mode: difference;
}

.clock {

  position: fixed;
  inset: 0;
  margin: auto;
  width: var(--clock-size);
  height: var(--clock-size);
  aspect-ratio: 1;
  place-content: center;
  background: var(--clock-clr);
  border-radius: 50%;
}
@media (width < 800px) {
  .clock {
    left: 0;
    right: auto;
    translate: calc((50% - 2rem) * -1) 0;
  }
}
/* semi transparent mask to hide not active time data*/
.clock::before {
  content: "";
  position: absolute;
  inset: 1px;
  margin: auto;
  background-color: rgba(0 0 0 / 0.85);
  clip-path: polygon(
    0 0,
    100% 0,
    100% 48%,
    50% 48%,
    50% 52%,
    100% 52%,
    100% 100%,
    0 100%
  );
  border-radius: 50%;
  z-index: 20;
}

.clock > div {
  position: absolute;
  inset: 0;
  margin: auto;
  width: var(--clock-d);
  height: var(--clock-d);
  font-size: var(--f-size, 0.9rem);
  aspect-ratio: 1;
  isolation: isolate;
  aspect-ratio: 1;
  border-radius: 50%;
}

/* years */
.clock > div:nth-of-type(1) {
  --clock-d: calc(var(--clock-size) - 20px);
}
/* seconds */
.clock > div:nth-of-type(2) {
  --clock-d: calc(var(--clock-size) - 130px);
}
/* minutes */
.clock > div:nth-child(3) {
  --clock-d: calc(var(--clock-size) - 195px);
}

/* hours */
.clock > div:nth-child(4) {
  --clock-d: calc(var(--clock-size) - 260px);
}
/* day numbers */
.clock > div:nth-child(5) {
  --clock-d: calc(var(--clock-size) - 350px);
}
/* month names  */
.clock > div:nth-child(6) {
  --clock-d: calc(var(--clock-size) - 470px);
}
/* day names*/
.clock > div:nth-child(7) {
  --clock-d: calc(var(--clock-size) - 600px);

}

.clock-face {
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  transition: 300ms linear;
}
.clock-face > * {
  position: absolute;
  transform-origin: center;
  white-space: nowrap;
  color: white;
  opacity: 0.75;

  &.active {
    opacity: 1;
  }
}

.clock > .current-lang-display {
  position: absolute;
  inset: 0;
  margin: auto;
  z-index: 100;
  display: grid;
  place-content: center;
  background-color: var(--clock-clr);
  border: 1px solid rgba(255 255 255 / 0.25);
  color: white;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  aspect-ratio: 1/1;
  cursor: pointer;
  transition: 300ms ease-in-out;
  font-size: 1.5rem;
  outline: none;
  &:focus-visible,
  &:hover {
    background-color: white;
  }
}
/* time seperators */
.current-lang-display::before,
.current-lang-display::after {
  content: ": ";
  color: white;
  position: absolute;
  z-index: 199;
  top: 50%;
  right: 0;
  font-size: 0.9rem;
  translate: 283px -10px;
}
.current-lang-display::after {
  font-size: 0.9rem;
  translate: 250px -10px;
}

/* Dialog styles */
dialog {
  width: min(calc(100% - 2rem), 380px);
  padding: 1rem;
  border: none;
  border-radius: 999px;
  background: rgba(255 255 255 / 0.05);
  text-align: center;
  aspect-ratio: 1;
  overflow: visible;

  @starting-style {
    opacity: 0;
    scale: 0;
  }
  transition: opacity 500ms ease-in,
    scale 500ms cubic-bezier(0.28, -0.55, 0.27, 1.55);
}
/* Backdrop styling */
dialog[open]::backdrop {
  background-color: rgba(from black r g b / 0.5);
  backdrop-filter: blur(3px);
  opacity: 1;
  @starting-style {
    opacity: 0;
  }
  transition: opacity 1000ms ease-in; /* this doesn't appear to be working */
}


dialog .btn-dialog-close {
  position: absolute;
  top: 0rem;
  right: 25%;
  aspect-ratio: 1;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: black;
  font-size: 1.2rem;
  color: white;
  border: none;
  outline: none;
  cursor: pointer;
  transition: rotate 300ms ease-in-out;
  z-index: 11;
  &:focus-visible,
  &:hover {
    rotate: 90deg;
  }
}

.language-options {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
  aspect-ratio: 1/1;
  overflow: hidden;
}
.language-options > label {
  position: absolute;
  transform: translate(-50%, -50%);
  cursor: pointer;
  font-size: 0.9rem;
  aspect-ratio: 1/1;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  transition: 300ms ease-in-out;
  display: grid;
  place-content: center;
  transform-origin: center;

  &.active {
    color: white;
    background: var(--clock-clr);
  }

  &:focus-visible,
  &:hover {
    scale: 1.1;
    z-index: 2;
  }
}
.language-title {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  color: white;
  font-size: 1.2rem;
  @starting-style {
    opacity: 0;
  }
  transition: opacity 300ms ease-in-out;
}
.flag-icon {
  font-size: 1.5rem;
  display: grid;
  place-content: center;
}
.language-options input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0, 0, 0, 0);
  overflow: hidden;
}
</style>


  
</head>

<body translate="no">
  <div class="clock" data-date="2024-12-25">
  <div>
    <div data-clock="years" data-numbers="101" class="clock-face"></div>
  </div>
  <div>
    <div data-clock="seconds" data-numbers="60" class="clock-face"></div>
  </div>
  <div>
    <div data-clock="minutes" data-numbers="60" class="clock-face"></div>
  </div>
  <div>
    <div data-clock="hours" data-numbers="24" class="clock-face"></div>
  </div>
  <div>
    <div data-clock="days" data-numbers="31" class="clock-face"></div>
  </div>
  <div>
    <div data-clock="months" data-numbers="12" class="clock-face"></div>
  </div>

  <div>
    <div data-clock="day-names" data-numbers="7" class="clock-face"></div>
  </div>
  <button type="button" id="current-lang" class="current-lang-display">en</button>
</div>

<dialog id="language-dialog">
  <button type="button" id="btn-dialog-close" class="btn-dialog-close " autofocus>&#10005;</button>
  <div id="language-options&.........完整代码请登录后点击上方下载按钮下载查看

网友评论0