每天一个小案例:SVG+Scss 彩色波浪线(附源码+效果)

109 阅读1分钟

我用SVG制作了波浪线,并移动了每条线,使运动和颜色不同步。它没有特别的用途。就是好玩

<div class="box"></div>
for (let i = 0; i < 20; i++) {
  $('.box').append('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 6"><path d="M0,1c25,0,25,4,50,4c25,0,25-4,50-4s25,4,50,4" /></svg>');
}
.box {
  font-size: 10px;
  width: 30em;
  height: 30em;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  svg {
    width: 35em;
    fill: none;
    @for $i from 1 through 20 {
      &:nth-child(#{$i}) {
        animation: Wavy 2s (0.1s * $i) ease-in-out infinite;
        stroke: adjust-hue(#f99, (20deg * $i));
      }
    }
  }
}

@keyframes Wavy {
  0% {
    transform: translateX(0);
    filter: hue-rotate(0deg);
    stroke-width: 1;
  }
  50% {
    transform: translateX(-5em);
    filter: hue-rotate(180deg);
    stroke-width: 1.5;
  }
  100% {
    transform: translateX(0);
    filter: hue-rotate(0deg);
    stroke-width: 1;
  }
}