js+svg实现鼠标触摸毛发动画效果代码

代码语言:html

所属分类:动画

代码描述:js+svg实现鼠标触摸毛发动画效果代码

代码标签: 触摸 毛发 动画 效果

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


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

<head>

  <meta charset="UTF-8">

  
  
<style>
@keyframes background {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 200px 200px;
  }
}
body {
  display: flex;
  width: 100vw;
  height: 100vh;
  align-items: center;
  animation: background 10s linear infinite;
  background-color: white;
  background-blend-mode: difference;
  background-size: 200px 200px;
  justify-content: center;
}

svg {
  background-color: white;
  overflow: visible !important;
}
svg circle {
  fill: black;
}
svg path {
  stroke-dasharray: 6 2;
  stroke-width: 1px;
}
</style>


</head>

<body  >
  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="345" height="345" viewBox="0 0 345 345" overflow="visible">
</svg>

  
      <script>
/* Properties */
const svg = {
  el: document.querySelector('svg'),
  path: document.querySelector('svg path'),
  width: 1,
  height: 1,
  x: 0,
  y: 0 };


const dots = [];

const circle = {
  radius: 3,
  margin: 20 };


const mouse = {
  x: 0,
  y: 0,
  prevX: 0,
  prevY: 0,
  speed: 0 };


const ticker = {
  fps: 60,
  fpsInterval: 1000 / 60,
  lastTickTime: null };


/* Resize */
function resizeHandler() {
  const bounding = svg.el.getBoundingClientRect();

  svg.width = bounding.width;
  svg.height = bounding.height;
  svg.x = bounding.left;
  svg.y = bounding.top;
}

/* Create dots */
function createDots() {
  resizeHandler();

  const dotSize = circle.radius + circle.margin;

  const rows = Math.floor(svg.height / dotSize);
  const cols = Math.floor(svg.width / dotSize);

  const x = svg.width % dotSize / 2;
  const y = svg.height .........完整代码请登录后点击上方下载按钮下载查看

网友评论0