gsap实现重力吸引鼠标跟随小球效果代码

代码语言:html

所属分类:其他

代码描述:gsap实现重力吸引鼠标跟随小球效果代码

代码标签: gsap 重力 吸引 鼠标 跟随 小球

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


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

<head>

  <meta charset="UTF-8">


  
  
<style>
*,
*:after,
*:before {
  box-sizing: border-box;
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  font-family: sans-serif, system-ui;
  touch-action: none;
  background: #18182f;
  cursor: -webkit-grab;
  cursor: grab;
}

.gravity-cursor {
  pointer-events: none;
  height: 50px;
  aspect-ratio: 1;
  background: white;
  border-radius: 50%;
  position: fixed;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%) translate(calc(var(--pointer-x) * 100vw), calc(var(--pointer-y) * 100vh)) scale(0.25);
  z-index: 3;
  transition: 0.1s;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

button svg {
  height: 44px;
  width: 44px;
  color: white;
}

.galaxy {
  height: 200px;
  width: 200px;
  background: hsl(var(--hue), 80%, 50%, 0.1);
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 50%;
  border: 2px solid hsl(var(--hue), 80%, 50%, 0.5);
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%) translate(calc(var(--x) * 1vw), calc(var(--y) * 1vh));
}

:root:has(.galaxy:hover) .gravity-cursor {
  transition: 0.2s;
  transform: translate(-50%, -50%) translate(calc(var(--gravity-x) * 100vw), calc(var(--gravity-y) * 100vh)) scale(1);
}

button {
  position: fixed;
  z-index: 10;
  bottom: 1rem;
  right: 1rem;
  font-size: 2rem;
  font-family: sans-serif;
  background: transparent;
  border: 0;
}

.galaxy__planet {
  height: 25%;
  aspect-ratio: 1;
  background: hsl(var(--hue), 60%, 70%);
  border-radius: 50%;
}
</style>


</head>

<body  >
  <div class="gravity-cursor"></div>
<div class="galaxy">
  <div class="galaxy__planet"></div>
</div>
<div class="galaxy">
  <div class="galaxy__planet"></div>
</div>
<div class="galaxy">
  <div class="galaxy__planet"></div>
</div>
<div class="galaxy">
  <div class="galaxy__planet"></div>
</div>
<div class="galaxy">
  <div class="galaxy__planet"></div>
</div>
<div class="galaxy">
  <div class="galax.........完整代码请登录后点击上方下载按钮下载查看

网友评论0