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

              
                <html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>22 - Imported models</title>
  <!-- <link rel="stylesheet" href="./style.css"> -->
</head>

<body>
  <main class="main">
    <div class="canvas-container">
      <canvas class="webgl"></canvas>
    </div>
    <div class="screens">
      <div class="screen panel fade fadeOut" id="screen1">SCREEN 1</div>
      <div class="screen2 panel fade fadeOut" id="screen2">SCREEN 2</div>
      <div class="screen3 panel fade fadeOut" id="screen3">SCREEN 3</div>
      <div class="screen4 panel fade fadeOut" id="screen4">SCREEN 4</div>
    </div>
  </main>
</body>

</html>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
}

html {
  font-size: 100%;
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
  vertical-align: baseline;
  border: 0;
}

body {
  font-size: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  background: white;
  overflow-x: hidden;
  overflow-y: scroll;
  width: 100vw;
  /* user-select: none; */
}
.webgl {
  position: fixed;
  top: 0;
  left: 0;
  outline: none;
}

.main {
  position: relative;
  width: 100%;
  height: 100%;
  top: 0;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  height: 100%;
  scroll-behavior: smooth;
}

.canvas-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}

.panel {
  border: unset;
  box-shadow: unset;
  margin-bottom: 0;
  border-radius: unset;
  opacity: 1;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  background-color: transparent;
  max-width: 1400px;
  margin: 0 auto;
  z-index: 1;
  position: relative;
  overflow: hidden;
  scroll-snap-align: start;
}

.screens {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  vertical-align: baseline;
  overscroll-behavior: none;
}

              
            
!

JS

              
                import { OrbitControls } from "https://cdn.skypack.dev/three@0.136.0/examples/jsm/controls/OrbitControls";
THREE.ColorManagement.enabled = false;

/**
 * Base
 */

// Canvas
const canvas = document.querySelector("canvas.webgl");

// Scene
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf7f7f7);

/**
 * Sizes
 */
const sizes = {
  width: window.innerWidth,
  height: window.innerHeight
};

/**
 * Camera
 */
// Base camera
const camera = new THREE.PerspectiveCamera(
  75,
  sizes.width / sizes.height,
  0.1,
  100
);
camera.position.set(0, 0, 2);
scene.add(camera);

// Controls
const controls = new OrbitControls(camera, document.body);
controls.enableDamping = true;
controls.enableRotate = false;
controls.enableZoom = false;
controls.rotateSpeed = 3;
controls.update();

/**
 * Renderer
 */
const renderer = new THREE.WebGLRenderer({
  canvas: canvas
});
renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setSize(sizes.width, sizes.height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));

let mixer = null;

const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({ color: 0x006800 });
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);

let geo = new THREE.EdgesGeometry(cube.geometry);
let mat = new THREE.LineBasicMaterial({ color: 0x074a07, linewidth: 10 });
let wireframe = new THREE.LineSegments(geo, mat);
cube.add(wireframe);

//gsap
gsap.registerPlugin(ScrollTrigger);

let tlScroll = gsap.timeline({
  duration: 1,
  scrollTrigger: {
    trigger: "body",
    endTrigger: "#screen2",
    start: "top top",
    end: "bottom bottom",
    scrub: 1,
    markers: true
  }
});

//Slide1
tlScroll.to(
  cube.rotation,
  {
    x: 0,
    duration: 1
  },
  "<"
);

gsap.to(camera.position, {
  x: 0,
  y: 0,
  z: 3,
  duration: 1,
  scrollTrigger: {
    trigger: "#screen2",
    endTrigger: "#screen3",
    start: "top top",
    end: "bottom bottom",
    markers: true,
    id: 2,
    scrub: 1
  }
});

let tlScroll2 = gsap.timeline({
  duration: 2,
  scrollTrigger: {
    trigger: "#screen3",
    endTrigger: "#screen4",
    start: "top top",
    end: "bottom bottom",
    scrub: 1,
    markers: true
  }
});

tlScroll2
  .to(cube.rotation, {
    x: 0.2,
    duration: 1
  })
  .to(
    cube.position,
    {
      y: 0.7,
      z: 1.2,
      duration: 1
    },
    "<"
  );

// simplified scrolling section
const sections = document.querySelectorAll(".panel");
let isScrolling = false;
function goToSection(section, anim, i) {
  if (!isScrolling) {
    isScrolling = true;
    gsap.to(window, {
      scrollTo: { y: section, autoKill: false },
      onComplete: () => (isScrolling = false),
      duration: 1
    });
  }
}
sections.forEach((section, i) => {
  ScrollTrigger.create({
    trigger: section,
    start: "top bottom-=1",
    end: "bottom top+=1",
    onEnter: () => goToSection(section),
    onEnterBack: () => goToSection(section)
  });
});

/**
 * Lights
 */
const ambientLight = new THREE.AmbientLight(0xffffff, 1);
scene.add(ambientLight);

const directionalLight = new THREE.DirectionalLight(0xffffff, 7);
directionalLight.castShadow = true;
directionalLight.shadow.mapSize.set(1024, 1024);
directionalLight.shadow.camera.far = 8;
directionalLight.shadow.camera.left = -8;
directionalLight.shadow.camera.top = 8;
directionalLight.shadow.camera.right = 8;
directionalLight.shadow.camera.bottom = -8;
directionalLight.position.set(0, 0.5, 0);
scene.add(directionalLight);

window.addEventListener("resize", () => {
  // Update sizes
  sizes.width = window.innerWidth;
  sizes.height = window.innerHeight;

  // Update camera
  camera.aspect = sizes.width / sizes.height;
  camera.updateProjectionMatrix();

  // Update renderer
  renderer.setSize(sizes.width, sizes.height);
  renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});

gsap.ticker.add(render);

function render() {
  renderer.render(scene, camera);
}

              
            
!
999px

Console