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%);
  --line1: hsl(193, 90%, 35%);
  --line2: hsl(203, 90%, 40%);
  --line3: hsl(213, 90%, 45%);
  --line4: hsl(var(--hue),90%,50%);
  --trans-dur: 0.3s;
  font-size: calc(14px + (30 - 14) * (100vw - 280px) / (3840 - 280));
}

body {
  background-color: var(--bg);
  color: var(--fg);
  display: flex;
  font: 1em/1.5 sans-serif;
  height: 100vh;
  transition: background-color var(--trans-dur), color var(--trans-dur);
}

.pl {
  --dur: 4s;
  display: block;
  margin: auto;
  width: 15em;
  height: auto;
}
.pl__line, .pl__line-wobble {
  animation-duration: var(--dur);
  animation-iteration-count: infinite;
  animation-timing-function: cubic-bezier(0.65, 0, 0.35, 1);
}
.pl__line {
  animation-name: line-move;
  animation-timing-function: cubic-bezier(0.33, 1, 0.67, 1);
  stroke: var(--line1);
  transition: stroke var(--trans-dur);
}
.pl__line:nth-child(2) {
  stroke: var(--line2);
}
.pl__line:nth-child(3) {
  stroke: var(--line3);
}
.pl__line:nth-child(4) {
  stroke: var(--line4);
}
.pl__line-wobble {
  animation-name: line-wobble;
}
.pl__lines:nth-child(8n) .pl__line:nth-child(1) {
  animation-delay: calc(var(--dur) * -0.0228);
}
.pl__lines:nth-child(8n) .pl__line:nth-child(2) {
  animation-delay: calc(var(--dur) * -0.0078);
}
.pl__lines:nth-child(8n) .pl__line:nth-child(3) {
  animation-delay: calc(var(--dur) * 0.0072);
}
.pl__lines:nth-child(8n) .pl__line:nth-child(4) {
  animation-delay: calc(var(--dur) * 0.0222);
}
.pl__lines:nth-child(8n) .pl__line-wobble {
  animation-delay: calc(var(--dur) * 0.0222);
}
.pl__lines:nth-child(8n+1) .pl__line:nth-child(1) {
  animation-delay: calc(var(--dur) * -0.6341);
}
.pl__lines:nth-child(8n+1) .pl__line:nth-child(2) {
  animation-delay: calc(var(--dur) * -0.6191);
}
.pl__lines:nth-child(8n+1) .pl__line:nth-child(3) {
  animation-delay: calc(var(--dur) * -0.6041);
}
.pl__lines:nth-child(8n+1) .pl__line:nth-child(4) {
  animation-delay: calc(var(--dur) * -0.5891);
}
.pl__lines:nth-child(8n+1) .pl__line-wobble {
  animation-delay: calc(var(--dur) * -0.5891);
}
.pl__lines:nth-child(8n+2) .pl__line:nth-child(1) {
  animation-delay: calc(var(--dur) * -0.3102);
}
.pl__lines:nth-child(8n+2) .pl__line:nth-child(2) {
  animation-delay: calc(var(--dur) * -0.2952);
}
.pl__lines:nth-child(8n+2) .pl__line:nth-child(3) {
  animation-delay: calc(var(--dur) * -0.2802);
}
.pl__lines:nth-child(8n+2) .pl__line:nth-child(4) {
  animation-delay: calc(var(--dur) * -0.2652);
}
.pl__lines:nth-child(8n+2) .pl__line-wobble {
  animation-delay: calc(var(--dur) * -0.2652);
}
.pl__lines:nth-child(8n+3) .pl__line:nth-child(1) {
  animation-delay: calc(var(--dur) * -0.9257);
}
.pl__lines:nth-child(8n+3) .pl__line:nth-child(2) {
  animation-delay: calc(var(--dur) * -0.9107);
}
.pl__lines:nth-child(8n+3) .pl__line:nth-child(3) {
  animation-delay: calc(var(--dur) * -0.8957);
}
.pl__lines:nth-child(8n+3) .pl__line:nth-child(4) {
  animation-delay: calc(var(--dur) * -0.8807);
}
.pl__lines:nth-child(8n+3) .pl__line-wobble {
  animation-delay: calc(var(--dur) * -0.8807);
}
.pl__lines:nth-child(8n+4) .pl__line:nth-child(1) {
  animation-delay: calc(var(--dur) * -0.593);
}
.pl__lines:nth-child(8n+4) .pl__line:nth-child(2) {
  animation-delay: calc(var(--dur) * -0.578);
}
.pl__lines:nth-child(8n+4) .pl__line:nth-child(3) {
  animation-delay: calc(var(--dur) * -0.563);
}
.pl__lines:nth-child(8n+4) .pl__line:nth-child(4) {
  animation-delay: calc(var(--dur) * -0.548);
}
.pl__lines:nth-child(8n+4) .pl__line-wobble {
  animation-delay: calc(var(--dur) * -0.548);
}
.pl__lines:nth-child(8n+5) .pl__line:nth-child(1) {
  animation-delay: calc(var(--dur) * -1.1217);
}
.pl__lines:nth-child(8n+5) .pl__line:nth-child(2) {
  animation-delay: calc(var(--dur) * -1.1067);
}
.pl__lines:nth-child(8n+5) .pl__line:nth-child(3) {
  animation-delay: calc(var(--dur) * -1.0917);
}
.pl__lines:nth-child(8n+5) .pl__line:nth-child(4) {
  animation-delay: calc(var(--dur) * -1.0767);
}
.pl__lines:nth-child(8n+5) .pl__line-wobble {
  animation-delay: calc(var(--dur) * -1.0767);
}
.pl__lines:nth-child(8n+6) .pl__line:nth-child(1) {
  animation-delay: calc(var(--dur) * -0.7793);
}
.pl__lines:nth-child(8n+6) .pl__line:nth-child(2) {
  animation-delay: calc(var(--dur) * -0.7643);
}
.pl__lines:nth-child(8n+6) .pl__line:nth-child(3) {
  animation-delay: calc(var(--dur) * -0.7493);
}
.pl__lines:nth-child(8n+6) .pl__line:nth-child(4) {
  animation-delay: calc(var(--dur) * -0.7343);
}
.pl__lines:nth-child(8n+6) .pl__line-wobble {
  animation-delay: calc(var(--dur) * -0.7343);
}
.pl__lines:nth-child(8n+7) .pl__line:nth-child(1) {
  animation-delay: calc(var(--dur) * -1.4695);
}
.pl__lines:nth-child(8n+7) .pl__line:nth-child(2) {
  animation-delay: calc(var(--dur) * -1.4545);
}
.pl__lines:nth-child(8n+7) .pl__line:nth-child(3) {
  animation-delay: calc(var(--dur) * -1.4395);
}
.pl__lines:nth-child(8n+7) .pl__line:nth-child(4) {
  animation-delay: calc(var(--dur) * -1.4245);
}
.pl__lines:nth-child(8n+7) .pl__line-wobble {
  animation-delay: calc(var(--dur) * -1.4245);
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: hsl(var(--hue),90%,10%);
    --fg: hsl(var(--hue),90%,90%);
  }
}
/* Animations */
@keyframes line-move {
  from, 35%, to {
    stroke-dashoffset: -6.99px;
  }
  50%, 85% {
    stroke-dashoffset: 4.99px;
  }
}
@keyframes line-wobble {
  from, to {
    stroke-width: 1px;
    transform: translate(0, 6.5px);
  }
  25% {
    stroke-width: 1.5px;
    transform: translate(0, 6.5px);
  }
  31.25% {
    stroke-width: 1px;
    transform: translate(0, 7px);
  }
  37.5% {
    stroke-width: 1.5px;
    transform: translate(0, 5px);
  }
  50% {
    stroke-width: 1px;
    transform: translate(0, 6.5px);
  }
  75% {
    stroke-width: 1.5px;
    transform: translate(0, 6.5px);
  }
  81.25% {
    stroke-width: 1px;
    transform: translate(0, 6px);
  }
  87.5% {
    stroke-width: 1.5px;
    transform: translate(0, 8px);
  }
}
</style>


  
  
</head>

<body translate="no">
  <svg class="pl" viewBox="0 0 32 32" width="32px" height="32px">
  <g stroke="currentcolor" stroke-linecap="round" stroke-width="1" stroke-dasharray="5 8">
    <g class="pl__lines" transform="rotate(0,16,16)">
      <g class="pl__line-wobble" transform="translate(0,6.5)">
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
      </g>
    </g>
    <g class="pl__lines" transform="rotate(-15,16,16)">
      <g class="pl__line-wobble" transform="translate(0,6.5)">
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
      </g>
    </g>
    <g class="pl__lines" transform="rotate(-30,16,16)">
      <g class="pl__line-wobble" transform="translate(0,6.5)">
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
      </g>
    </g>
    <g class="pl__lines" transform="rotate(-45,16,16)">
      <g class="pl__line-wobble" transform="translate(0,6.5)">
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
      </g>
    </g>
    <g class="pl__lines" transform="rotate(-60,16,16)">
      <g class="pl__line-wobble" transform="translate(0,6.5)">
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
      </g>
    </g>
    <g class="pl__lines" transform="rotate(-75,16,16)">
      <g class="pl__line-wobble" transform="translate(0,6.5)">
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
      </g>
    </g>
    <g class="pl__lines" transform="rotate(-90,16,16)">
      <g class="pl__line-wobble" transform="translate(0,6.5)">
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
      </g>
    </g>
    <g class="pl__lines" transform="rotate(-105,16,16)">
      <g class="pl__line-wobble" transform="translate(0,6.5)">
        <line class="pl__line" x1="16" y1="16" x2="16" y2="23"></line>
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0