gsap实现鼠标任意位置点击成群爬虫出现交互动画效果代码

代码语言:html

所属分类:动画

代码描述:gsap实现鼠标任意位置点击成群爬虫出现交互动画效果代码

代码标签: gsap 鼠标 任意 位置 点击 成群 爬虫 出现 交互 动画

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

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

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

  
<style>
body {
  font: bold 100%/1 sans-serif;
}

.flex {
  align-items: center;
  display: flex;
  justify-content: center;
}

.scene {
  background-color: white;
  height: 100vh;
}

.canvas svg {
  position: absolute;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
}
.canvas svg:hover {
  cursor: pointer;
}

p {
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
  pointer-events: none;
}
</style>

  
</head>

<body >
  <section class="flex scene">
	<figure class="canvas">
		<svg viewBox="0 0 1600 900" role="presentational" />
	</figure>
	<p>
		Click anywhere
	</p>
</section>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.9.1.js"></script>
      <script  >
(function(){
	const svg = document.querySelector("svg");
	const isAnimationOk = window.matchMedia('(prefers-reduced-motion: no-preference)').matches;
	const positions = [-250, -200, -175, -150, -125, -200, -75, -50, 50, 75, 125, 150, 175, 200, 250];
	const shapeCount = 14;
	let mouse = {
		x: window.innerWidth/2,
		y: window.innerHeight/2
	};

	setViewBox();
	
	svg.addEventListener("click", function(e) {
		setMouseCoords(e);
		animate();
	});
	
	window.addEventListener('resize', function(e) {
		setViewBox();
	});

	function setMouseCoords(event) {
		mouse.x = event.clientX;
		mouse.y = event.clientY;
	}

	function setViewBox() {
		svg.setAttribute("viewBox", `0 0 ${window.innerWidth} ${window.innerHeight}`);
	}

	function animate() {
		let elements = [];

		for (let i = 0; i < shapeCount; i++) {
			let newElement = document.createElementNS("http://www.w3.org/2000/svg", "path");
			newElement.setAttribute("d", `M${mouse.x},${mouse.y}c0.499,-1.289 -0.146,-2.734 -1.435,-3.223c-1.289,-0.488 -2.734,0.146 -3.222,1.435l-3.379,8.794c-0.821,2.152 -0.312,4.585 1.32,6.207l5.967,5.967l-8.358,-2.786c-0.249,-0.083 -0.447,-0.281 -0.53,-0.53l-1.965,-5.905c-0.436,-1.31 -1.85,-2.017 -3.16,-1.58c-1.31,0.436 -2.017,1.85 -1.58,3.16l1.965,5.905c0.582,1.736 1.944,3.098 3.68,3.68l6.299,2.1l-6.289,2.1c-1.736,0.582 -3.098,1.944 -3.68,3.68l-1.975,5.904c-0.437,1.31 0.27,2.724 1.58,3.161c1.31,0.436 2.724,-0.271 3.16,-1.58l1.965,-5.90.........完整代码请登录后点击上方下载按钮下载查看

网友评论0