js实现跟随鼠标的烟花尾巴绽放动画效果代码

代码语言:html

所属分类:动画

代码描述:js实现跟随鼠标的烟花尾巴绽放动画效果代码

代码标签: js 跟随 鼠标 烟花 尾巴 绽放 动画

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

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

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

  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  
  
<style>
body {
	background: #111;
	overflow: hidden;
}
#motionSimulation {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 100%;
	height: 100%;
}
</style>


  
  
</head>

<body translate="no">
  <svg id="motionSimulation" viewBox="0 0 200 100" preserveAspectRatio="none">
	<circle id="getMe" r="0" fill="none">
		<animateMotion dur="10s" repeatCount="indefinite" path="M20,50 C20,-50 180,150 180,50 C180-50 20,150 20,50 z" />
	</circle>
</svg>
  
      <script  >
let sparkInterval;
function spark(event, opt_properties) {
  let mouseX, mouseY;
  if (event) {
    mouseX = event.clientX;
    mouseY = event.clientY;
  }
  const defaultProperties = { color: `random`, mouseX: mouseX, mouseY: mouseY, hw: 30, sparks: 8, sw: 8, time: 400 };
  const randInt = (min, max) => {return Math.floor(Math.random() * (max - min + 1)) + min;};
  const c = Object.assign(defaultProperties, opt_properties);
  const col = c.color === 'random' ? `rgb(${randInt(0, 255)}, ${randInt(0, 255)}, ${randInt(0, 255)})` : c.color;
  const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  svg.setAttribute("viewBox", "0 0 100 100");
  svg.setAttribute("style", `wi.........完整代码请登录后点击上方下载按钮下载查看

网友评论0