Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                  <main>
        <div id="container" class="container">
            <div class="row justify-content-center align-items-center mb-5">
                <div class="col-12 col-lg-4">
                    <img src="https://via.placeholder.com/300x200">
                    <h2 class="my-3">Hello ceci est un titre</h2>
                    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quam harum laboriosam, assumenda
                        dolorum,
                        facere modi corrupti beatae, placeat exercitationem cupiditate ab. Assumenda modi odio beatae
                        consequuntur vero deserunt accusamus veritatis?</p>
                </div>
                <div class="col-12 col-lg-8">
                    <img src="https://via.placeholder.com/300x500">
                    <h2 class="my-3">Hello ceci est un titre</h2>
                    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quam harum laboriosam, assumenda
                        dolorum,
                        facere modi corrupti beatae, placeat exercitationem cupiditate ab. Assumenda modi odio beatae
                        consequuntur vero deserunt accusamus veritatis?</p>
                </div>
            </div>
            <div class="row justify-content-center align-items-center mb-5">
                <div class="col-12 col-lg-8">
                    <img  src="https://via.placeholder.com/300x250">
                    <h2 class="my-3">Hello ceci est un titre</h2>
                    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quam harum laboriosam, assumenda
                        dolorum,
                        facere modi corrupti beatae, placeat exercitationem cupiditate ab. Assumenda modi odio beatae
                        consequuntur vero deserunt accusamus veritatis?</p>
                </div>
                <div class="col-12 col-lg-4">
                    <img  src="https://via.placeholder.com/300x800">
                    <h2 class="my-3">Hello ceci est un titre</h2>
                    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quam harum laboriosam, assumenda
                        dolorum,
                        facere modi corrupti beatae, placeat exercitationem cupiditate ab. Assumenda modi odio beatae
                        consequuntur vero deserunt accusamus veritatis?</p>
                </div>
            </div>
            <div class="row justify-content-center align-items-center mb-5">
                <div class="col-12 col-lg-6">
                    <img  src="https://via.placeholder.com/300x100">
                    <h2 class="my-3">Hello ceci est un titre</h2>
                    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quam harum laboriosam, assumenda
                        dolorum,
                        facere modi corrupti beatae, placeat exercitationem cupiditate ab. Assumenda modi odio beatae
                        consequuntur vero deserunt accusamus veritatis?</p>
                </div>
                <div class="col-12 col-lg-6">
                    <img  src="https://via.placeholder.com/300x450">
                    <h2 class="my-3">Hello ceci est un titre</h2>
                    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quam harum laboriosam, assumenda
                        dolorum,
                        facere modi corrupti beatae, placeat exercitationem cupiditate ab. Assumenda modi odio beatae
                        consequuntur vero deserunt accusamus veritatis?</p>
                </div>

            </div>
        </div>
    </main>
    <div id="canvas"></div>
              
            
!

CSS

              
                #canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

img {
  width: 100%;
  opacity: 0.5;
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

window.onload = () => {
  /* Settings */
  let time = 0;
  const container = document.getElementById("canvas");
  const scene = new THREE.Scene();

  let width = container.offsetWidth;
  let height = container.offsetHeight;

  const camera = new THREE.PerspectiveCamera(70, width / height, 100, 2000);
  camera.position.z = 600;
  camera.fov = 2 * Math.atan(height / 2 / 600) * (180 / Math.PI);
  const renderer = new THREE.WebGLRenderer({
    antialias: true,
    alpha: true,
  });

  container.appendChild(renderer.domElement);

  const images = [...document.querySelectorAll("img")];
  const imageInCanvas = images.map((img) => {
    let bounds = img.getBoundingClientRect();
    const geometry = new THREE.PlaneBufferGeometry();

    const material = new THREE.MeshBasicMaterial({
      color: 0xff0000,
    });

    const mesh = new THREE.Mesh(geometry, material);
    mesh.scale.set(bounds.width, bounds.height, 1);
    scene.add(mesh);


    /* GSAP scroll test */

    // gsap.fromTo(
    //   mesh.position,
    //   {
    //     y: () => -img.height / 2 - height / 2,
    //   },
    //   {
    //     y: () => img.height / 2 + height / 2,
    //     ease: "none",
    //     scrollTrigger: {
    //       trigger: img,
    //       from: "top bottom",
    //       to: "bottom top",
    //       scrub: true,
    //       invalidateOnRefresh: true,
    //       markers: true,
    //     },
    //   }
    // );
    
    let tween;
    onRefresh();
    
    function onRefresh() {
      
      tween && tween.progress(0);
      
      let height = container.offsetHeight;
      
      tween = gsap.fromTo(mesh.position, {
        y: () => -img.height / 2 - height / 2,
      }, {
        y: () => img.height / 2 + height / 2,
        ease: "none",
        paused: true
      })
    }
        
    ScrollTrigger.create({
      trigger: img,
      from: "top bottom",
      to: "bottom top",
      onUpdate({ progress }) {
        tween.progress(progress);
        // renderer.render(scene, camera);
      },
      onRefresh({ progress}) {
        onRefresh();
        tween.progress(progress);
      }
    })

    return {
      img: img,
      mesh: mesh,
      top: bounds.top,
      left: bounds.left,
      width: bounds.width,
      height: bounds.height,
    };
  });

  imageInCanvas.forEach((o) => {
    o.mesh.position.x = o.left - width / 2 + o.width / 2;
  });

  /* Resize & animate */
  window.addEventListener("resize", () => resize());

  const resize = function () {
    if (imageInCanvas) {
      let width = container.offsetWidth;
      let height = container.offsetHeight;
      camera.fov = 2 * Math.atan(height / 2 / 600) * (180 / Math.PI);
      renderer.setSize(width, height);
      camera.aspect = width / height;
      camera.updateProjectionMatrix();

      imageInCanvas.forEach((o) => {
        let bounds = o.img.getBoundingClientRect();
        o.left = bounds.left;
        o.width = bounds.width;
        o.height = bounds.height;
        o.mesh.position.x = o.left - width / 2 + o.width / 2;
        o.mesh.scale.set(bounds.width, bounds.height, 1);
      });
    }
  };
  resize();
  
  gsap.ticker.add(() => {
    renderer.render(scene, camera);
  });
  
  // ScrollTrigger.create({
  //   onUpdate() {
  //     renderer.render(scene, camera);
  //   }
  // })
  
  // const animate = function () {
  //   time += 0.05;
  //   window.requestAnimationFrame(animate);
  //   renderer.render(scene, camera);
  // };
  // animate();
};

              
            
!
999px

Console