svg+js实现鼠标跟随风扇散热交互动画效果代码

代码语言:html

所属分类:动画

代码描述:svg+js实现鼠标跟随风扇散热交互动画效果代码,移动鼠标靠近小人,小人就会凉爽,背景颜色就会改变,使用了warpjs对svg进行变形。

代码标签: svg js 鼠标 跟随 风扇 散热 交互 动画

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


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

<head>

  <meta charset="UTF-8">
  


  
  
<style>
@keyframes spin {
  from {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}
@keyframes sweat {
  0% {
    transform: translate(-50%, -50%) translateY(0);
    opacity: 1;
  }
  20% {
    transform: translate(-50%, -50%) translateY(25px);
    opacity: 1;
  }
  30% {
    transform: translate(-50%, -50%) translateY(0);
    opacity: 0;
  }
  100% {
    transform: translate(-50%, -50%) translateY(0);
    opacity: 0;
  }
}
:root {
  --person-scale: 1;
  --mouth-scale: 1;
  --background: #fdc830;
  --fan: 80px;
  --fan-animation-duration: 1.8s;
}

html,
body {
  height: 100%;
  cursor: none;
  background: var(--background);
  transition: background 0.25s ease-out;
}
html:after,
body:after {
  content: "";
  background: radial-gradient(circle, rgba(0, 0, 0, 0) 52%, rgba(18, 18, 18, 0.35) 100%);
  width: 100%;
  height: 100%;
  position: absolute;
}

.person {
  overflow: visible;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(var(--person-scale));
}

.fan {
  position: absolute;
  width: var(--fan);
  height: var(--fan);
  transform: translate(-50%, -50%);
  animation: spin var(--fan-animation-duration) linear infinite;
}

.eyes {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.eye {
  position: relative;
  display: inline-block;
  border-radius: 50%;
  height: 30px;
  width: 30px;
  background: #CCC;
  transition: 0.25s width ease-in;
}
.eye:before {
  position: absolute;
  bottom: 17px;
  right: 10px;
  width: 10px;
  height: 10px;
  background: #000;
  border-radius: 50%;
  content: " ";
}

.mouth {
  height: 20px;
  width: 28px;
  border-radius: 100%;
  background: #CCC;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(var(--mouth-scale));
  transform-origin: center;
  transition: 0.25s transform ease-in;
  margin-top: 40px;
}

.sweat {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateY(25px);
  margin: -50px 0 0 -50px;
  opacity: 0;
  transition: 0.25s all ease-out;
  animation: sweat 4s ease-out infinite;
}
.sweat:after {
  display: block;
  content: "";
  background: #2e8ece;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  transform: scale(0.7, 1) rotate(45deg);
}

.close {
  --background: #0cebeb;
  --fan: 65px;
  --fan-animation-duration: 0.8s;
}

.veryClose {
  --background: #29ffc6;
  --fan: 50px;
  --fan-animation-duration: 0.5s;
  --person-scale: 0.85;
  --mouth-scale: 0.4;
}
.veryClose .sweat {
  display: none;
}
</style>



</head>

<body  >
  <div class="person">
	<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
		<circle cx="100" cy="100" r="100"/>
	</svg>
</div>


<div class='eyes'>
  <div class='eye'></div>
  <div class='eye'></div>
</div>

<div class="mouth"></div>

<div class='sweat'></div>

<svg class="fan" viewBox="0 0 799.8 800.4">
		<path d="M501.4,336.1c4.4-3.4,8.6-6.6,12.8-9.8c32.5-25.2,69.1-41.5,109.3-49.1c23.7-4.5,48.1-5.2,71.6,0
			c30.4,6.7,55.1,23.6,73.8,48.9c18.1,24.6,27,52.3,29.8,82.5c4,41.7-2.2,81.4-22.3,118.5c-10.6,19.5-24.7,36-46.5,43.3
			c-34.6,11.6-66.4,7.8-93.1-19.3c-9.2-9.4-17.9-19.3-26.8-29c-14.3-15.4-28.4-31-45.8-43c-15.9-11-33.2-18.2-52.5-20.5
			c-3.8-0.4-6.6,0-9,3.5c-9.8,14.4-20.9,27.6-35.5,37.6c-0.9,0.6-1.4,3.4-0.8,4.4c1.8,3.1,4.3,5.9,6.6,8.8
			c25.6,32.8,42.6,69.6,50.3,110.4c4.5,23.9,5,48.3,0.1,72.1c-6.4,30.9-24.2,55.2-49.2,74.2c-21.4,16.2-45.8,24.7-72.2,28.4
			c-43.4,6.1-85.1,1.2-124.5-18.8c-19.2-9.8-35.5-22.9-45.1-43c-13.3-27.7-12.3-72.5,16..........完整代码请登录后点击上方下载按钮下载查看

网友评论0