svg+css实现炫酷过渡动画的开关点击切换效果代码

代码语言:html

所属分类:布局界面

代码描述:svg+css实现炫酷过渡动画的开关点击切换效果代码

代码标签: svg css 炫酷 过渡 动画 开关 点击 切换

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

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

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

  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  
  
  
<style>
* {
  border: 0;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --hue: 223;
  --bg: hsl(var(--hue),90%,90%);
  --fg: hsl(var(--hue),90%,10%);
  --trans-dur: 0.3s;
  --trans-timing: cubic-bezier(0.65,0,0.35,1);
  font-size: calc(14px + (30 - 14) * (100vw - 280px) / (3840 - 280));
}

body,
button {
  color: var(--fg);
  font: 1em/1.5 sans-serif;
}

body {
  background-color: var(--bg);
  display: flex;
  height: 100vh;
  transition: background-color var(--trans-dur), color var(--trans-dur);
}

.btn {
  background-color: transparent;
  border-radius: 1em;
  box-shadow: 0 0 0 0.25em hsla(var(--hue), 90%, 50%, 0), 0 0 0 0.0625em hsla(var(--hue), 90%, 50%, 0) inset;
  cursor: pointer;
  margin: auto;
  outline: transparent;
  width: 8em;
  height: 8em;
  transition: box-shadow calc(var(--trans-dur) / 2), transform calc(var(--trans-dur) / 2);
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active {
  transform: scale(0.9);
}
.btn:focus-visible {
  box-shadow: 0 0 0 0.25em hsla(var(--hue), 90%, 50%, 1), 0 0 0 0.0625em hsla(var(--hue), 90%, 50%, 1) inset;
}
.btn__icon {
  display: block;
  pointer-events: none;
  width: 100%;
  height: auto;
}
.btn__icon-bg-off, .btn__icon-bg-on, .btn__icon-radar, .btn__icon-ring, .btn__icon-line {
  animation-duration: 0.6s;
  animation-timing-function: var(--trans-timing);
  animation-fill-mode: forwards;
}
.btn[aria-pressed=false] .btn__icon-radar {
  animation-name: radar-off;
}
.btn[aria-pressed=false] .btn__icon-ring {
  animation-name: ring-off;
  transform: rotate(90deg);
  transform-origin: 8px 8px;
}
.btn[aria-pressed=false] .btn__icon-line {
  animation-name: line-off;
}
.btn[aria-pressed=true] .btn__icon-bg-on {
  animation-name: bg-on;
}
.btn[aria-pressed=true] .btn__icon-ring {
  animation-name: ring-on;
}
.btn[aria-pressed=true] .btn__icon-line {
  animation-name: line-on;
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: hsl(var(--hue),90%,10%);
    --fg: hsl(var(--hue),90%,90%);
  }
}
/* Animations */
@keyframes bg-on {
  from {
    transform: translate(0, -32px);
  }
  to {
    transform: translate(0, 0);
  }
}
@keyframes line-off {
  from {
    stroke-dashoffset: 0;
  }
  to {
    stroke-dashoffset: -48;
  }
}
@keyframes line-on {
  from {
    stroke-dashoffset: 30;
  }
  to {
    stroke-dashoffset: 0;
  }
}
@keyframes radar-off {
  from {
    stroke-dashoffset: 0;
  }
  to {
    stroke-dashoffset: 58.3;
  }
}
@keyframes ring-off {
  from {
  .........完整代码请登录后点击上方下载按钮下载查看

网友评论0