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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <div class="circle">
  <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
    <circle id="circle" cx="50" cy="50" r="4" stroke="green" stroke-width="1px" fill-opacity="0"/>
  </svg>
</div>

<div class="scroller">
  <svg viewBox="0 0 100 65" xmlns="http://www.w3.org/2000/svg">
    <polygon points="0,0 20,0 50,40 80,0 100,0 50,65" stroke="green" stroke-width="1px" fill="green"/>
  </svg>
  <svg viewBox="0 0 100 65" xmlns="http://www.w3.org/2000/svg">
    <polygon points="0,0 20,0 50,40 80,0 100,0 50,65" stroke="green" stroke-width="1px" fill="green"/>
  </svg>
  <svg viewBox="0 0 100 65" xmlns="http://www.w3.org/2000/svg">
    <polygon points="0,0 20,0 50,40 80,0 100,0 50,65" stroke="green" stroke-width="1px" fill="green"/>
  </svg>
</div>

<div class="loader">Loading<div></div><div></div><div></div></div>
<div class="watermark">Models and resources from <a href="https://trek.nasa.gov/">NASA</a></div>

<div class="section welcome"></div>
<div class="content">
  <div class="section olympus">
    <div class="section__content">
      <div class="title"></div>
      <div class="info">
        <div class="info__row">
          <div class="coords">
            <div class="lat"></div>
            <div class="lon"></div>
            <div class="nav">
              <svg viewBox="0 0 100 100" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg">
                <polyline id="line" points="20,5 50,100 100,100" fill="none" stroke="green" stroke-width="1px"/>
              </svg>
            </div>
          </div>
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/PIA00300_hires.jpg" />
            </div>
          </div>
        </div>
        <div class="info__row">
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/calderaOMons_marsexpress_lg.jpg" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="section curiosity">
    <div class="section__content">
      <div class="title"></div>
      <div class="info">
        <div class="info__row">
          <div class="coords">
            <div class="lat"></div>
            <div class="lon"></div>
            <div class="nav">
              <svg viewBox="0 0 100 100" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg">
                <polyline id="line" points="20,5 50,100 100,100" fill="none" stroke="green" stroke-width="1"/>
              </svg>
            </div>
          </div>
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/575963main_PIA14297_full.jpg" />
            </div>
          </div>
        </div>
        <div class="info__row">
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/673885main_PIA15986-full_full.jpg" />
            </div>
          </div>
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/713264main_pia16457-full_full.jpg" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="section valles">
    <div class="section__content">
      <div class="title"></div>
      <div class="info">
        <div class="info__row">
          <div class="coords">
            <div class="lat"></div>
            <div class="lon"></div>
            <div class="nav">
              <svg viewBox="0 0 100 100" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg">
                <polyline id="line" points="20,5 50,100 100,100" fill="none" stroke="green" stroke-width="1"/>
              </svg>
            </div>
          </div>
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/581433main_PIA00425_full.jpg" />
            </div>
          </div>
        </div>
        <div class="info__row">
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/pia21274.jpg" />
            </div>
          </div>
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/pia21651.jpg" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="section medusae">
    <div class="section__content">
      <div class="title"></div>
      <div class="info">
        <div class="info__row">
          <div class="coords">
            <div class="lat"></div>
            <div class="lon"></div>
            <div class="nav">
              <svg viewBox="0 0 100 100" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg">
                <polyline id="line" points="20,5 50,100 100,100" fill="none" stroke="green" stroke-width="1"/>
              </svg>
            </div>
          </div>
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/PIA00809_hires.jpg" />
            </div>
          </div>
        </div>
        <div class="info__row">
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/PIA23522_hires.jpg" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="section cydonia">
    <div class="section__content">
      <div class="title"></div>
      <div class="info">
        <div class="info__row">
          <div class="coords">
            <div class="lat"></div>
            <div class="lon"></div>
            <div class="nav">
              <svg viewBox="0 0 100 100" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg">
                <polyline id="line" points="20,5 50,100 100,100" fill="none" stroke="green" stroke-width="1"/>
              </svg>
            </div>
          </div>
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/PIA02381_hires.jpg" />
            </div>
          </div>
        </div>
        <div class="info__row">
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/face2001_mgs.jpg" />
            </div>
          </div>
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/PIA04745_hires.jpg" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="section tharsis">
    <div class="section__content">
      <div class="title"></div>
      <div class="info">
        <div class="info__row">
          <div class="coords">
            <div class="lat"></div>
            <div class="lon"></div>
            <div class="nav">
              <svg viewBox="0 0 100 100" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg">
                <polyline id="line" points="20,5 50,100 100,100" fill="none" stroke="green" stroke-width="1"/>
              </svg>
            </div>
          </div>
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/PIA00408_hires.jpg" />
            </div>
          </div>
        </div>
        <div class="info__row">
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/PIA02049_hires.jpg" />
            </div>
          </div>
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/pia11176.jpg" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="section deimos">
    <div class="section__content">
      <div class="title"></div>
      <div class="info">
        <div class="info__row">
          <div class="coords">
            <div class="lat"></div>
            <div class="lon"></div>
            <div class="nav">
              <svg viewBox="0 0 100 100" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg">
                <polyline id="line" points="20,5 50,100 100,100" fill="none" stroke="green" stroke-width="1"/>
              </svg>
            </div>
          </div>
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/318064main_pia11826-full_full.jpg" />
            </div>
          </div>
        </div>
        <div class="info__row">
          <div>
            <div class="image-container">
              <img class="image" src="https://assets.codepen.io/1443237/283561main_phobos2_hirise_big_full.jpg" />
            </div>
          </div>
          <div>

          </div>
        </div>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                @import (css) url(https://fonts.googleapis.com/css2?family=Play:wght@400;700&display=swap);

body {
  margin: 0;
  overflow-x: hidden;
  background-color: black;
}

canvas {
  position:fixed;
  top: 0;
}

svg {
  height:100%;
  width:100%;
  vector-effect: non-scaling-stroke;
}

.watermark {
  position: fixed;
  font: 18px Play;
  color: white;
  z-index: 3;
  right: 0;
  bottom: 0;
  padding: 10px;
  visibility: hidden;
}
.loader {
  font: 68px Play;
  font-weight: bold;
  z-index: 3;
  color: green;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  div {
    + div {
      margin-left: 4px;
    }
    height: 10px;
    width: 10px;
    background: green;
    display: inline-block;

    animation: load 1s ease-in alternate-reverse infinite;
    &:nth-child(2) {
      animation-delay: 0.33s;
    }
    &:nth-child(3) {
      animation-delay: 0.66s;
    }
  }
}

.circle, .scroller {
  z-index:3;
  position: fixed;
}
.circle {
  height:100%;
  width:100%;

  svg {
    visibility: hidden;
  }
}
.scroller {
  display: flex;
  flex-direction: column;
  left: 50%;
  bottom: 4%;
  transform: translate(-50%, 0);
  visibility: hidden;
  svg {
    width: 8vmin;
    height: auto;

    polygon {
      animation: scroll 1s ease-in alternate-reverse infinite;
    }
    &:nth-child(2) {
      transform: translate(0, -1vmin);
      polygon {
        animation-delay: 0.33s;
      }
    }
    &:nth-child(3) {
      transform: translate(0, -2vmin);
      polygon {
        animation-delay: 0.66s;
      }
    }
  }
}
.section {
  font-family: 'Play', sans-serif;
  height: 100vh;
  width: 100vw;
  color: white;
  z-index: 1;
  position: relative;
  display: inline-block;

  &__content {
    padding: 4vmin;
    position:fixed;
    color:green;
    z-index: 2;
    top:0;
    height: calc(100vh - 8vmin);
    width: calc(100vw - 8vmin);
    display: flex;
    flex-direction: column;

    svg {
      visibility: hidden;
    }

    .title {
      font-size: 54px;
      font-weight: bold;
    }

    .info {
      height: 0;
      flex-grow: 1;
      display: flex;
      flex-direction: column;

      &__row {
        display: flex;
        flex-grow: 1;
        height: 50%;

        > div {
          flex-grow: 1;
          width:100%;
        }

        .coords {
          font-size: 24px;
          > div {
            &:last-child {
              height: calc(100vh/2 - 4vmin - 114px);
              width:100%;
            }
          }
        }

        .image-container {
          border: 2px solid green;
          visibility: hidden;
          overflow: hidden;
          position: relative;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          max-height: 100%;

          .image {
            width: 100%;
            display: block;
          }
        }
      }
    }

    .editing {
      &:after {
        content: "_";
      }
    }

    .blink {
      &:after {
        animation: blink 1s steps(5, start) infinite;
      }
    }
  }

  &.olympus, &.medusae {
    .info {
      height: 0;
      flex-direction: row;

      &__row {
        flex-direction: column;
        width: 50%;
        height: 100%;
        // display: inline-block;

        .image-container {
          width: 50%;

          .image {
            width: 100%;
          }
        }

        &:first-child {
          > div {
            height: 50%;
          }
        }
      }
    }
  }
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

@keyframes scroll {
  0% {
    fill-opacity: 0;
  }

  100% {
    fill-opacity: 1;
  }
}

@keyframes load {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}
              
            
!

JS

              
                Math.degToRad = degrees => degrees * (Math.PI / 180);

class Scene {
  constructor(urls) {
    this._urls = urls;
  }

  init() {
    return new Promise((resolve) => {
      let models = [];
      const manager = new THREE.LoadingManager(() => {
        this.setupCanvas(models);
        resolve();
      });
      const loader = new THREE.GLTFLoader(manager);
      this._urls.forEach(x => loader.load(x.url, gltf => {
        gltf.scene.visible = x.visible;
        models.push({ id: x.id, scene: gltf.scene });
      }))
    });
  }
  setupCanvas(models) {
    // Camera
    this.camera = new THREE.PerspectiveCamera( 25, window.innerWidth / window.innerHeight, 1, 30000 );
    this.camera.position.set(0, 0, 4000);

    // Scene
    this.scene = new THREE.Scene();

    // Renderer
    this.renderer = new THREE.WebGLRenderer();
    this.renderer.setSize(window.innerWidth, window.innerHeight);
    this.renderer.outputEncoding = THREE.sRGBEncoding;
    this.renderer.setPixelRatio(window.devicePixelRatio);

    // Light
    const ambientLight = new THREE.AmbientLight(0x111111);
    this.scene.add(ambientLight);

    const directionalLight = new THREE.DirectionalLight(0xffffff);
    directionalLight.position.set(2, 0, 1).normalize();
    this.scene.add(directionalLight);

    models.forEach(x => {
      this[x.id] = x.scene;
      this.scene.add(this[x.id]);
    })

    document.body.appendChild(this.renderer.domElement);

    this.render();
    this.animate();

    window.addEventListener('resize', () => {
      this.camera.aspect = window.innerWidth / window.innerHeight;
      this.camera.updateProjectionMatrix();
      this.renderer.setSize(window.innerWidth, window.innerHeight);
      this.render();
    }, false);
  }
  animate() {
    this.render();
    requestAnimationFrame(() => this.animate());
  }
  render() {
    this.renderer.render(this.scene, this.camera);
  }
}

class Page {
  constructor(scene) {
    this._scene = scene;
  }

  get mars() {
    return this._scene.mars;
  }

  get deimos() {
    return this._scene.deimos;
  }

  get camera() {
    return this._scene.camera;
  }

  get content() {
    return     [
      {
        title: 'Olympus Mons',
        coords: {
          Latitude: '18.65275889',
          Longitude: '-133.8025067'
        },
        selector: '.olympus'
      },
      {
        title: 'Gale Crater',
        coords: {
          Latitude: '136.783441',
          Longitude: '-5.10837943'
        },
        selector: '.curiosity'
      },
      {
        title: 'Valles Marineris',
        coords: {
          Latitude: '-14.00586857',
          Longitude: '-58.5876741'
        },
        selector: '.valles'
      },
      {
        title: 'Medusae Fossae',
        coords: {
          Latitude: '-2.166284249',
          Longitude: '-164.1956286'
        },
        selector: '.medusae'
      },
      {
        title: 'Cydonia',
        coords: {
          Latitude: '39.66724753',
          Longitude: '0'
        },
        selector: '.cydonia'
      },
      {
        title: 'Tharsis Volcanic Region',
        coords: {
          Latitude: '-2.623623306',
          Longitude: '-116.7076259'
        },
        selector: '.tharsis'
      },
      {
        title: 'Deimos',
        coords: {
          Distance: '23,460 km',
          Radius: '6.2 km'
        },
        selector: '.deimos'
      },
    ];
  }
  async init() {
    window.onbeforeunload = function () {
      window.scrollTo(0,0);
    };
    await this._scene.init();
    document.querySelector('.loader').style.display = 'none';
    this.setupPlugins();
    this.setupAnimScrollTrigger();
    this.setupContentScrollTrigger();
  }
  setupPlugins() {
    gsap.registerPlugin(ScrollTrigger);
    gsap.registerPlugin(TextPlugin);
    gsap.registerPlugin(DrawSVGPlugin);
  }
  setupAnimScrollTrigger() {
    const opening = new gsap.timeline()
      .fromTo(this.camera.position, {z: 2000}, {z: 4000, ease: 'Circ.easeOut', duration: 1.5}, 'opening')
      .fromTo(this.camera.rotation, {y: -Math.degToRad(30), x: -Math.degToRad(-5)}, {y: 0, x: 0, ease: 'Circ.easeOut', duration: 1.5}, 'opening')
      .set(".scroller, .watermark",{visibility: "visible"});

    const rotation = new gsap.timeline({
        scrollTrigger: {
          toggleActions: "play pause play pause",
          trigger: ".welcome",
          start: "top bottom",
          end: "top -1",
        }
      })
      .to(this.mars.rotation, {y:Math.degToRad(360), ease:'none', repeat:-1, duration: 30});

    const animation = new gsap.timeline({
        scrollTrigger: {
          trigger: ".content",
          scrub: true,
          start: "top bottom",
          end: "bottom bottom",
          //markers: {startColor: "green", endColor: "red", fontSize: "12px"}
        }
      })
      .set(".nav svg, .circle svg",{visibility: "visible"})
      .to(this.mars.rotation, {y: Math.degToRad(133.8025067+90), x: Math.degToRad(18.65275889), ease: 'power2.inOut', duration: 0.75}, 0)
      .to(this.camera.position, {z:3000, ease: 'linear', duration: 0.75}, 0)
      .set(".scroller",{visibility: "hidden"}, 0.2)
      .to(this.mars.rotation, {y: -Math.degToRad(136.78344100200877-90), x: Math.degToRad(5.1083794384352), ease: 'power2.inOut', duration: 0.75}, 1)
      .to(this.mars.rotation, {y: Math.degToRad(58.5876741+90), x: Math.degToRad(-14.00586857), ease: 'power2.inOut', duration: 0.75}, 2)
      .to(this.mars.rotation, {y: Math.degToRad(164.1956286+90), x: Math.degToRad(-2.166284249), ease: 'power2.inOut', duration: 0.75}, 3)
      .to(this.mars.rotation, {y: Math.degToRad(90), x: Math.degToRad(39.66724753), ease: 'power2.inOut', duration: 0.75}, 4)
      .to(this.mars.rotation, {y: Math.degToRad(116.7076259+90), x: Math.degToRad(-2.623623306), ease: 'power2.inOut', duration: 0.75}, 5)
      .to(this.camera.position, {z: 22000, ease: 'linear'}, 6)
      .to(this.camera.rotation, {z: Math.degToRad(10), y: Math.degToRad(10), ease: 'power2.inOut', duration: 0.75}, 6)
      .set(this.deimos, {visible: true}, 6)
      .to(this.deimos.scale, {x:7, y:7, z:7, ease: 'linear', duration: 0}, 6)
      .fromTo(this.deimos.position, {x: -500, y:0, z: 22000}, {x: -170, y: 0, z: 21000, ease: 'power2.inOut', duration: 0.75}, 6)
  }
  setupContentScrollTrigger(){
    const onUpdate = function() {
      const target = this.targets()[0];
      const time = this.time();
      const duration = this.duration();

      if (time >= duration || time <= 0) {
        target.classList.remove('editing');
        return;
      }
      if (!target.classList.contains('editing')) {
        target.classList.add('editing');
      }
    };

    const getLines = obj => {
      const lines = [];
      Object.keys(obj).forEach(x => {
        lines.push(`${x}: ${obj[x]}`);
      });
      return lines;
    };

    ScrollTrigger.addEventListener("scrollEnd", function(e){
      const target = document.querySelectorAll('.editing')[0];
      if (target) {
        target.classList.add('blink');
      }
    });

    ScrollTrigger.addEventListener("scrollStart", function(e){
      const target = document.querySelectorAll('.editing')[0];
      if (target) {
        target.classList.remove('blink');
      }
    });

    this.content.forEach((item, i, arr) => {
      const timeline = new gsap.timeline({
          scrollTrigger: {
            trigger: item.selector,
            scrub: true,
            start: 'top 75%',
            end: `bottom ${i < arr.length - 1 ? '75%' : 'bottom'}`,
            //markers: {startColor: "green", endColor: "red", fontSize: "12px"}
          }
        })
        .to(`${item.selector} .title`, {text:`${item.title}`, ease: 'linear', duration: 0.25, onUpdate}, 0)
        .to(`${item.selector} .lat`, {text: `${getLines(item.coords)[0]}`, ease: 'linear', duration: 0.125, onUpdate}, 0.25)
        .to(`${item.selector} .lon`, {text: `${getLines(item.coords)[1]}`, ease: 'linear', duration: 0.125, onUpdate}, 0.375)
        .fromTo(`${item.selector} polyline`, {drawSVG: 0}, {drawSVG: '100%', duration: 0.125}, 0.5)
        .fromTo('#circle', {drawSVG: 0}, {drawSVG: '100%', duration: 0.125}, 0.625)
        .set(`${item.selector} .image-container`, {visibility: 'visible'})
        .fromTo(`${item.selector} .image-container`, {width: '0%'}, {width: '25vw', duration: 0.125}, 0.75)
        .fromTo(`${item.selector} .image-container`, {height: '0%'}, {height: 'auto', duration: 0.125}, 0.875);

      if(i < arr.length - 1) {
        timeline.yoyo(true)
                .repeat(1)
                .repeatDelay(0.5);
      }
    });
  }
}

const urls =[
  {
    id: 'mars',
    url: 'https://assets.codepen.io/1443237/Mars_1_6792.glb',
    visible: true
  },
  {
    id: 'deimos',
    url: 'https://assets.codepen.io/1443237/Deimos_1_1000.glb',
    visible: false
  }
];

new Page(new Scene(urls)).init();
              
            
!
999px

Console