Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                #app
svg.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")
              
            
!

CSS

              
                *
  box-sizing border-box

body
  min-height 100vh
  background radial-gradient(hsl(210, 80%, 6%), hsl(0, 0%, 2%)), hsl(210, 80%, 6%)

#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 hsl(0, 0%, 90%)
  animation action 4s infinite

@keyframes action
  0%, 25%, 50%, 100%
    transform translate(0, 0)
  12.5%, 37.5%
    transform translate(0, 25%)
              
            
!

JS

              
                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        
  }, [])
 
  return (
    <mesh ref={globeRef} castShadow={true} >
      <sphereGeometry args={[1, 32, 16]} />
      <meshPhongMaterial
        map={world}
        bumpMap={bump}
        bumpScale={0.5}
        color={WORLD_COLOR}
        shininess={SHINE}
      />
    </mesh>
  );
};

const WorldGlobe = () => {
  const globeRef = React.useRef(null);
  React.useEffect(() => {
    if (globeRef.current) {
      gsap.to(globeRef.current.rotation, {
        y: Math.PI / 180 * 360,
        ease: 'none',
        repeat: -1,
        duration: 20,
      })      
    }
  }, [])
  return (
    <group ref={globeRef}>
      {/* Globe w/ Axis */}
      <group rotation={[0, Math.PI / 180 * 40, (Math.PI / 180) * 16]}>
        <mesh position={[0, 0, 0]} rotation={[0, 0, Math.PI / 180 * 80]} castShadow={true}>
          <torusGeometry
            args={[
              1.1,
              0.05,
              32,
              32,
              Math.PI / 180 * 200,
            ]}
          />
          <meshPhongMaterial shininess={SHINE} color={FRAME_COLOR} />
        </mesh>
        <mesh position={[0, 0, 0]} castShadow={true}>
          <cylinderGeometry args={[0.025, 0.025, 2.4, 30]} />
          <meshPhongMaterial shininess={SHINE} color={FRAME_COLOR} />
        </mesh>
        <Globe />
      </group>
      {/* The Stand it comes on */}
      <group position={[0, -1.6, 0]}>
        <mesh position={[0, 0.25, 0]} castShadow={true}>
          <cylinderGeometry args={[0.1, 0.1, 0.5, 30]} />
          <meshPhongMaterial shininess={SHINE} color={FRAME_COLOR} />
        </mesh>
        <mesh castShadow={true}>
          <cylinderGeometry args={[0.8, 0.8, 0.16, 30]}/>
          <meshPhongMaterial shininess={SHINE} color={FRAME_COLOR} />
        </mesh>
      </group>
    </group>
  );
};

const App = () => {
  return (
    <div className="container">
      <Canvas resize={{ debounce: { scroll: 50, resize: 10 } }} shadows={true}>
        <pointLight castShadow={true} args={[0xffffff, 1, 0, 2]} position={[20, 20, 15]} />
        <pointLight args={[0xffffff, 1, 0, 2]} position={[-50, 30, -10]} />
        <WorldGlobe />
        <mesh rotation={[Math.PI / 180 * -90, 0, 0]} position={[0, -2, 0]} receiveShadow={true}>
          <circleGeometry args={[20, 20]}/>
          <shadowMaterial />
        </mesh>
      </Canvas>
    </div>
  );
};

ReactDOM.render(<App />, ROOT_NODE);

              
            
!
999px

Console