css+div实现大转盘时间线点击切换效果代码

代码语言:html

所属分类:布局界面

代码描述:css+div实现大转盘时间线点击切换效果代码

代码标签: css div 大转盘 时间 线 点击 切换

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

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

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


  
  
<style>
/* Hide radio buttons */
input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}
.cards-container {
  --base-rotation: 0deg;
  --full-circle: 360deg;
  --radius: 40vw;
  --duration: 200ms;
  
  --cards-container-size: calc(var(--radius) * 2);
  --cards-container-padding: 2rem;

  --border-color: transparent;
  
  --label-offset: calc(var(--radius) * -1 - 1rem);
  --label-size: 30px;
  --label-color: #666;
  --label-color-hover: steelblue;
  --label-line-h: 0;
  --label-line-h-current: 2rem;
  --label-dot-size: 10px;

  --title-top: 1.5rem;
  --title-offset-y: 30px;

  --info-top: 5rem;
  --info-width: 80%;
  --info-offset-y: 30px;

  box-sizing: content-box;
  position: fixed;
  inset: 0;
  margin: auto;
  width: var(--cards-container-size);
  height: var(--cards-container-size);
  
  padding: var(--cards-container-padding);
  clip-path: polygon(0 0, 100% 0, 100% 50%, 0 50%);
}
@media (min-width: 800px) {
  .cards-container {
    --radius: 30vw;
    --label-size: 40px;
    --label-dot-size: 15px;
    --label-line-h-current: 4rem;
    --title-top: 4rem;
    --info-top: 8rem;
  }
}
@media (min-width: 1200px) {
  .cards-container {
 
    --label-size: 50px;
    --border-color: var(--label-color);
    --info-width: min(100% - 2rem, 65%);
    
  }
}
.cards {
  position: absolute;
  inset: var(--cards-container-padding);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  transition: transform 0.3s ease-in-out var(--duration);
  list-style: none;
}



.cards li {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  transform-origin:center;
  display: grid;
  place-content: center;
  transform: rotate(calc(var(--i) * 360deg / var(--items)));
  pointer-events: none;
}

.cards li > label {
  position: absolute;
  inset: 0;
  margin: auto;
  transform: translateY(var(--label-offset));
  width: var(--label-size);
  height: var(--label-size);
  cursor: pointer;
  pointer-events: initial;
  text-align: center;
  color: var(--label-color);
  transition: var(--duration) ease-in-out;

}
.cards li > label::before{
    content: '';
    position: absolute;
    top: var(--cards-container-padding);
    left: 50%;
    translate: -50% 0;
    width: var(--label-dot-size);
    height: var(--label-dot-size);
    aspect-ratio: 50%;
    border-radius: 50%;
    background-color: var(--label-color);
    transition: background-color var(--duration) ease-in-out;
}

.cards li > label::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  translate: -50% 5px;
  width: 2px;
  height: var(--label-line-h);
  background-color: steelblue;
  transition: height 300ms ease-in-out var(--label-line-delay,0ms);
}
.cards li > label:hover{
  --label-color: var(--label-color-hover);
}

.cards > li > h2,
.cards > li > p{
  position: absolute;
  left: 50%;
  text-align: center;
  transform: translate(-50%, 0);
  transform-origin: center;
}
.cards > li > h2{
  top: var(--title-top);
  opacity: var(--title-opacity,0);
  translate: 0 var(--title-offset-y);
  transition: var(--duration) ease-in-out var(--title-delay,0ms);
}
.cards > li > p{
  top: var(--info-top);
  margin: 0 auto;
  width: var(--info-width);
  z-index: 2;
  font-size: clamp(.8rem, 2.5vw + 0.05rem, .9rem);
  text-wrap: balance;
  opacity: var(--info-opacity,0);
  translate: 0 var( --info-offset-y);
  transition: var(--duration) ease-in-out var(--info-delay,0ms);
}

/* update custom properties for checked item */
li:has(input:checked){
    --label-opacity: 1;
    --label-color: var(--label-color-hover);
    --label-line-h: var(--label-line-h-current);
    --label-line-delay: calc(var(--duration) * 2);

    --title-opacity: 1;
    --title-offset-y: 0;
    --title-delay: calc(var(--duration) * 3);

    --info-opacity: 1;
    --info-offset-y: 0;
    --info-delay: calc(var(--duration) * 4);
    /*outline: 1px dashed red;*/
}

/* rotate container based on checked radio */
.cards:has(input:checked) {
  transform: rotate(calc(var(--base-rotation) - (var(--index) * var(--full-circle) / var(--items))));
}
/*
this would be so much simpler if we could use counter values as custom property values
*/
.cards:has(li:nth-child(1)>input:checked) { --index: 0; }
.cards:has(li:nth-child(2)>input:checked) { --index: 1; }
.cards:has(li:nth-child(3)>input:checked) { --index: 2; }
.cards:has(li:nth-child(4)>input:checked) { --index: 3; }
.cards:has(li:nth-child(5)>input:checked) { --index: 4; }
.cards:has(li:nth-child(6)>input:checked) { --index: 5; }
.cards:has(li:nth-child(7)>input:checked) { --index: 6; }
.cards:has(li:nth-child(8)>input:checked) { --index: 7; }
.cards:has(li:nth-child(9)>input:checked) { --index: 8; }
.cards:has(li:nth-child(10)>input:checked) { --index: 9; }
.cards:has(li:nth-child(11)>input:checked) { --index: 10; }
.cards:has(li:nth-child(12)>input:checked) { --index: 11; }
.cards:has(li:nth-child(13)>input:checked) { --index: 12; }
.cards:has(li:nth-child(14)>input:checked) { --index: 13; }
.cards:has(li:nth-child(15)>input:checked) { --index: 14; }
.cards:has(li:nth-child(16)>input:checked) { --index: 15; }
.cards:has(li:nth-child(17)>input:checked) { --index: 16; }
.cards:has(li:nth-child(18)>input:checked) { --index: 17; }
.cards:has(li:nth-child(19)>input:checked) { --index: 18; }
.cards:has(li:nth-child(20)>input:checked) { --index: 19; }
.cards:has(li:nth-child(21)>input:checked) { --index: 20; }
.cards:has(li:nth-child(22)>input:checked) { --index: 21; }
.cards:has(li:nth-child(23)>input:checked) { --index: 22; }
.cards:has(li:nth-child(24)>input:checked) { --index: 23; }
.cards:has(li:nth-child(25)>input:checked) { --index: 24; }
.cards:has(li:nth-child(26)>input:checked) { --index: 25; }



/* general styling */
*,
::before,
::after {
  box-sizing: border-box;
}
:root {
  --clr-bg: #222;
  --clr-primary: #f5f5f5;
  --clr-secondary: #075985;
}
html {
  background-color: var(--clr-bg);
  font-family: system-ui;
}

body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  line-height: 1.4;
  color: var(--clr-primary);
  padding: 1rem;
  margin: 0;
  background-image: radial-gradient(
    circle,
    rgba(175, 208, 84, 0.25) 1px,
    rgba(0, 0, 0, 0) 1px
  );
  background-size: 40px 40px;
  background-attachment: fixed;
}
button,
input,
optgroup,
select,
textarea {
  font-family: inherit;
  font-size: 100%;
  line-height: 1.15;
  margin: 0;
}
h1 {
  font-size: clamp(1rem, 2.5vw + 0.25rem, 1.2rem);
  font-weight: 500;
  line-height: 1.6;
}
code,
pre {
  display: inline-block;
  color: #38bdf8;
  border: 1px solid hsl(from var(--clr-primary) h s 50% / 0.5);
  padding: 0.5rem 1rem;
  border-radius: 5px;
}
pre {
  white-space: pre-wrap;
}
em {
  font-size: 0.8rem;
}
body::after {
  content: "";
  position: fixed;
  top: 1rem;
  left: 1rem;
  width: 32px;
  height: 32px;
  background-size: cover;
  background-image: url('data:image/svg+xml,<svg id="logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100" version="1.1"><g id="surface1"><path fill="rgb(175, 208, 84)" d="M 47.894531 0.789062 C 46.320312 0.878906 45.480469 0.949219 44.601562 1.042969 C 37.023438 1.863281 29.746094 4.394531 23.386719 8.414062 C 20.214844 10.421875 17.402344 12.65625 14.757812 15.285156 C 7.773438 22.222656 3.027344 30.992188 1.113281 40.5 C -0.460938 48.332031 -0.132812 56.378906 2.070312 64.003906 C 4.0625 70.890625 7.507812 77.195312 12.277344 82.675781 C 16.65625 87.714844 22.109375 91.898438 28.074219 94.804688 C 37.914062 99.59375 49.078125 101.031.........完整代码请登录后点击上方下载按钮下载查看

网友评论0