点击查看html编辑器说明文档

CSS吃豆人开关edit icon

|
|
Fork(复制)
|
|
作者:
穿越者X57

👉 新版编辑器已上线,点击进行体验吧!

BUG反馈
嵌入
设置
下载
HTML
格式化
支持Emmet,输入 p 后按 Tab键试试吧!
<head> ...
展开
</head>
<body>
            
            <input type="checkbox" role="switch" class="pacman" />
<input type="checkbox" role="switch" class="pacman" checked />
<input type="checkbox" role="switch" class="pacman" disabled />
<input type="checkbox" role="switch" class="pacman" disabled checked />

<input type="checkbox" role="switch" class="pacman no-animation" />
<input type="checkbox" role="switch" class="pacman indeterminate" />
        
</body>
CSS
格式化
            
            body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin: 0;
  min-height: 100vh;
  font-size: 5vmin;
  background: #123;
  gap: 0.5em;
}

@keyframes waka_waka_waka {
  to { transform: translate(-50%, var(--translation)) rotate(var(--rotation)); }
}

@keyframes boooooo {
  to { transform: translate(-50%, -55%); }
}

.pacman {
  --waka-speed: 0.2s;
  --speed: 0.5s;
  appearance: none;
  position: relative;
  font-size: 1em;
  width: 3em;
  aspect-ratio: 3;
  border: max(1px, 0.05em) solid #fff;
  border-radius: 2em;
  box-sizing: content-box;
  background:
    linear-gradient(90deg, #123 6em, #1230 0) -5.5em 0 / 9em 100%,
    radial-gradient(circle, #fff 0.075em, #fff0 0.08em) 50% 0 / 0.4em 100%,
    #123;
  transition: background-position calc(var(--speed) * 4) linear;
  
  &::before, &::after {
    --rotation: 30deg;
    --translation: -100%;
    content: "";
    position: absolute;
    width: 0.8em;
    height: 0.4em;
    background: yellow;
    border-radius: 50% / 100% 100% 0 0;
    top: 50%;
    left: 0.5em;
    transform-origin: 50% 100%;
    transform: translate(-50%, var(--translation)) rotate(0);
    transition: left calc(var(--speed)) linear;
    animation: waka_waka_waka var(--waka-speed) alternate infinite;
  }
  
  &::after {
    --rotation: -30deg;
    --translation: 0;
    border-radius: 50% / 0 0 100% 100%;
    transform-origin: 50% 0;
  }
  
  &:checked {
    background-position: 2.5em 0, 50% 0;
    
    &::before, &::after {
      --rotation: -30deg;
      left: calc(100% - 0.5em);
    }
    
    &::after {
      --rotation: 30deg;
    }
  }
  
  &.no-animation, &[disabled] {
    &, &::before, &::after {
      transition: none !important;
      animation-play-state: paused !important;
      animation-delay: calc(var(--speed) / -2) !important;
    }
    
    &::before { --rotation: -30deg; }
    &::after { --rotation: 30deg; }
    &:checked {
      &::before { --rotation: 30deg; }
      &::after { --rotation: -30deg; }
    }
  }
  
  &[disabled] {
    opacity: 0.25;
  }
  
  &:indeterminate {
    background: #123;
    
    &::before {
      content: none;
    }
    
    &::after {
      animation: boooooo 0.5s alternate infinite;
      left: 50%;
      transform: translate(-50%, -50%);
      height: 0.8em;
      width: 0.7em;
      background:
        radial-gradient(circle at 30% 40%, #123 0.07em, #0000 0.08em),
        radial-gradient(circle at 70% 40%, #123 0.07em, #0000 0.08em),
        yellow
        ;
      border-radius: 2em 2em 0 0;
      clip-path: polygon(0 0, 100% 0, 100% 100%, 83.33% 85%, 66.66% 100%, 50% 85%, 33.33% 100%, 16.66% 85%, 0 100%);
    }
  }
}

@media print {
  .pacman {
    &, &::before, &::after {
      -webkit-print-color-adjust: exact;
      print-color-adjust: exact;
    }
  }
}

@media (prefers-reduced-motion) {
  .pacman {
    &, &::before, &::after {
      transition: none !important;
      animation-play-state: paused !important;
      animation-delay: calc(var(--speed) / -2) !important;
    }
  }
}

@media (prefers-contrast: more) {
  .pacman {
    &::before, &::after {
      background-color: highlight !important;
    }
  }
}
        
JS
格式化
            
            document.querySelector(".indeterminate").indeterminate = true;
        
预览
控制台