gsap+three实现三维地球仪效果代码

代码语言:html

所属分类:三维

代码描述:gsap+three实现三维地球仪效果代码

代码标签: gsap three 三维 地球仪

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

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

<head>

  <meta charset="UTF-8">
  


  
  
<style>
* {
  box-sizing: border-box;
}
body {
  min-height: 100vh;
  background: radial-gradient(#030f1c, #050505), #030f1c;
}
#app {
  display: grid;
  place-items: center;
  min-height: 100vh;
}
.container {
  position: fixed;
  height: 100vh;
  width: 100vw;
  transform: translate3d(0, 0, 100vmin);
}
.scroll-icon {
  height: 30px;
  position: fixed;
  top: 1rem;
  right: 1rem;
  color: #e6e6e6;
  -webkit-animation: action 4s infinite;
          animation: action 4s infinite;
}
@-webkit-keyframes action {
  0%, 25%, 50%, 100% {
    transform: translate(0, 0);
  }
  12.5%, 37.5% {
    transform: translate(0, 25%);
  }
}
@keyframes action {
  0%, 25%, 50%, 100% {
    transform: translate(0, 0);
  }
  12.5%, 37.5% {
    transform: translate(0, 25%);
  }
}
</style>


</head>

<body >
  <div id="app"></div>
<svg class="scroll-icon" viewBox="0 0 24 24">
  <path fill="currentColor" d="M20 6H23L19 2L15 6H18V18H15L19 22L23 18H20V6M9 3.09C11.83 3.57 14 6.04 14 9H9V3.09M14 11V15C14 18.3 11.3 21 8 21S2 18.3 2 15V11H14M7 9H2C2 6.04 4.17 3.57 7 3.09V9Z"></path>
</svg>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.9.1.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/ScrollTrigger.min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Observer.min.js"></script>
      <script  type="module">
import React from "https://cdn.skypack.dev/react@17.0.0";
import {
Canvas,
useFrame,
useLoader } from
"https://cdn.skypack.dev/@react-three/fiber@7.0.0";
import * as THREE from "https://cdn.skypack.dev/three@v0.138.0";
import ReactDOM from "https://cdn.skypack.dev/react-dom@17.0.0";

gsap.registerPlugin(Observer);

const ROOT_NODE = document.querySelector("#app");

const TEXTURE_URL =
"https://assets.codepen.io/605876/world-map-texture.png?format=auto&quality=48";
const BUMP_URL =
"https://assets.codepen.io/605876/world-map-texture-bump.png?format=auto&quality=48";

const FRAME_COLOR = "hsl(40, 50%, 30%)";
const WORLD_COLOR = "hsl(0, 0%, 75%)";
const PLANE_COLOR = "hsl(0, 0%, 5%)";
const SHINE = 155;

const Globe = () => {
  const world = new THREE.TextureLoader().load(TEXTURE_URL);
  const bump = new THREE.TextureLoader().load(BUMP_URL);
  const globeRef = React.useRef(null);

  React.useEffect(() => {

    const spinTo = dest => gsap.to(globeRef.current.rotation, { y: `+=${Math.PI / 180 * dest}` });

    if (globeRef.current) {
      Observer.create({
        type: "wheel,touch,scroll,pointer",
        preventDefault: true,
        onUp: ({ deltaY, velocityY }) => {
          const SPIN = gsap.utils.mapRange(-10000, 0, -1080, 0, velocityY);
          spinTo(SPIN);
        },
        onDown: ({ deltaY, velocityY }) => {
          const SPIN = gsap.utils.mapRange(0, 10000, 0, 1080, velocityY);
          spinTo(SPIN);
        },
        tolerance: 10 });

    }
    // Set up the scroll listener in here for spinning the globe .........完整代码请登录后点击上方下载按钮下载查看

网友评论0