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 {
	cursor: pointer;
	background: #345;
}
svg {
	height: 400px;
	width: 400px;
	position: absolute;
}
small {
	color: #ddd;
	font-family: monospace;
	text-align: center;
/* 	width: 100%; */
	position: relative;
	user-select: none;
	pointer-events: none;
}
</style>


  
</head>

<body translate="no">
  <small>move your dirty <i>dirty</i> mouse around</small>
  
      <script >
const randInt = (min, max) => {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
function germ(e) {
	let mouseX, mouseY;
	let event = e;
	if (!e) {
		event = window.event;
		mouseX = window.innerWidth/2;
		mouseY = window.innerHeight/2;
	}
	if (event && (event.pageX || event.pageY)) {
		mouseX = event.pageX;
		mouseY = event.pageY;
	}
	else if (event && (event.clientX || event.clientY))    {
		mouseX = event.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	let pp = '';
	for (let i=0; i<randInt(1,3); i++) {
		let x = 50;
		let y = 55;
		let w = randInt(5, 15);
		let h = randInt(2, 10);
		let d1 = `M ${x} ${y} q ${randInt(w/10, w/1.1)} ${h} ${w} 0`;
		let d2 = `M ${x} ${y + randInt(0,h)} q ${randInt(w/10, w/1.1)} -${h} ${w} 0`;
		let rot = randInt(0,360);
		let fadeOut = randInt(1500,2500);
		let sw = randInt(50, 200)/100;
		let p = `<g transform="rotate(${randInt(0,360)} 50 50)">
		<path d="${d1}" stroke="rgb(0, ${randInt(130, 255)}, ${randInt(0, 150)})" stroke-width="${sw.........完整代码请登录后点击上方下载按钮下载查看

网友评论0