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="center-mark"></div>
<div class="doors">
  <div class="door-container door-container-left">
    <div class="door door-left"></div>
  </div>
  <div class="door-container door-container-right">
    <div class="door door-right"></div>
  </div>
</div>

<div class="content">
  <div class="content-container content-home" id="content-home">
    Lorem Ipsum is simply dummy text of<br />the printing and typesetting
    industry.
  </div>
  
  <div class="content-container content-image" id="content-image">
  </div>
</div>

<div class="scroll-container">
  <section class="section space">Initial</section>
  <section class="section home-in">Home In</section>
  <section class="section home">Home</section>
  <section class="section home-out">Home Out</section>
  <section class="section space">Space</section>
  <section class="section image-in">Image In</section>
  <section class="section image">Image</section>
  <section class="section image-out">Image Out</section>
  <section class="section space">Final</section>
</div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Open+Sans&display=swap");

body {
  background-color: #333333;
  font-family: sans-serif;
  margin: 0;
  padding: 0;
}

/*! locomotive-scroll v4.1.3 | MIT License | https://github.com/locomotivemtl/locomotive-scroll */
html.has-scroll-smooth {
  overflow: hidden;
}

html.has-scroll-dragging {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.has-scroll-smooth body {
  overflow: hidden;
}

.has-scroll-smooth [data-scroll-container] {
  min-height: 100vh;
}

[data-scroll-direction="horizontal"] [data-scroll-container] {
  height: 100vh;
  display: inline-block;
  white-space: nowrap;
}

[data-scroll-direction="horizontal"] [data-scroll-section] {
  display: inline-block;
  vertical-align: top;
  white-space: nowrap;
  height: 100%;
}

.c-scrollbar {
  position: absolute;
  right: 0;
  top: 0;
  width: 11px;
  height: 100%;
  transform-origin: center right;
  transition: transform 0.3s, opacity 0.3s;
  opacity: 0;
}
.c-scrollbar:hover {
  transform: scaleX(1.45);
}
.c-scrollbar:hover,
.has-scroll-scrolling .c-scrollbar,
.has-scroll-dragging .c-scrollbar {
  opacity: 1;
}
[data-scroll-direction="horizontal"] .c-scrollbar {
  width: 100%;
  height: 10px;
  top: auto;
  bottom: 0;
  transform: scaleY(1);
}
[data-scroll-direction="horizontal"] .c-scrollbar:hover {
  transform: scaleY(1.3);
}

.c-scrollbar_thumb {
  position: absolute;
  top: 0;
  right: 0;
  background-color: black;
  opacity: 0.5;
  width: 7px;
  border-radius: 10px;
  margin: 2px;
  cursor: -webkit-grab;
  cursor: grab;
}
.has-scroll-dragging .c-scrollbar_thumb {
  cursor: -webkit-grabbing;
  cursor: grabbing;
}
[data-scroll-direction="horizontal"] .c-scrollbar_thumb {
  right: auto;
  bottom: 0;
}

/* Center Mark */

.center-mark {
  background-color: black;
  height: 100vh;
  left: 50%;
  position: fixed;
  top: 0;
  transform: translateX(-1px);
  width: 2px;
  z-index: 7000;
}

/* Doors */

.doors {
  align-items: center;
  display: flex;
  justify-content: center;
  left: 50%;
  opacity: 1;
  pointer-events: none;
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5000;
  width: 100%;
}

.door-container {
  display: flex;
  height: 300px;
  left: 0;
  position: absolute;
  width: 50%;
}

.door-container-left {
  transform-origin: right center;
  transform: translateX(-100%);
}

.door-container-right {
  transform-origin: left center;
  transform: translateX(0%);
}

.door {
  height: 300px;
  left: 0;
  position: absolute;
  width: 100%;
}

.door-left {
  background-color: orangered;
}

.door-right {
  background-color: orange;
}

/* Content */

.content {
  color: white;
  left: 50%;
  pointer-events: none;
  position: fixed;
  top: 50%;
  z-index: 4000;
}

.content-container {
  font-family: "Open Sans", sans-serif;
  opacity: 0;
  position: absolute;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  visibility: hidden;
}

.content-container-active {
  opacity: 1;
  visibility: visible;
}

.content-home {
  font-size: 30px;
}

.content-image {
  max-height: 300px;
}

@media (min-width: 1024px) {
  .content-home {
    font-size: 60px;
  }
}

/* Sections */

.section {
  color: rgba(255, 255, 255, 0.8);
  background-color: #333333;
  border-bottom: 1px solid #111111;
  font-size: 14px;
  min-height: 100vh;
  padding: 20px 0 0 20px;
  text-transform: uppercase;
  width: 100%;
}

.section {
  min-height: 100vh;
}

.section.space {
  min-height: 200vh;
}

              
            
!

JS

              
                (function () {
  
  gsap.registerPlugin(ScrollTrigger);
  
  // ---------------------------------------------------------------
  // Contents
  // ---------------------------------------------------------------
  
  const CONTENT_ACTIVE_CLASS = 'content-container-active'
  
  const contentHome = document.getElementById("content-home");
  const contentImage = document.getElementById('content-image')
  
  function showContent (content) {
    content.classList.add(CONTENT_ACTIVE_CLASS)
  }
  
  function hideContent (content) {
    content.classList.remove(CONTENT_ACTIVE_CLASS)
  }
  
  // ---------------------------------------------------------------
  // Random Image
  // ---------------------------------------------------------------

  let currentImage = null

  function addRandomImage () {
    const randomImage = document.getElementById('random-image')
    if (randomImage) randomImage.remove()
    
    const randomWidth = Math.round(Math.random()*200);
    const img = document.createElement('img');
    img.id = 'random-image'
    img.src = `https://picsum.photos/${400 + randomWidth}/300`;
    contentImage.appendChild(img);
    
    img.addEventListener('load', function _listener () {
      currentImage = img;
      ScrollTrigger.refresh();      
      img.removeEventListener('load', _listener);
    })
  }
  
  addRandomImage();
  
  // ---------------------------------------------------------------
  // Locomotive Scroll
  // ---------------------------------------------------------------

  const scrollContailerClass = ".scroll-container";

  const locoScroll = new LocomotiveScroll({
    el: document.querySelector(scrollContailerClass),
    smooth: true,
    multiplier: 0.5
  });

  locoScroll.on("scroll", ScrollTrigger.update);

  // ---------------------------------------------------------------
  // ScrollTrigger config proxy
  // ---------------------------------------------------------------

  ScrollTrigger.scrollerProxy(scrollContailerClass, {
    scrollTop(value) {
      if (arguments.length) {
        return locoScroll.scrollTo(value, 0, 0);
      }
      return locoScroll.scroll.instance.scroll.y;
    },
    getBoundingClientRect() {
      return {
        top: 0,
        left: 0,
        width: window.innerWidth,
        height: window.innerHeight
      };
    },
    pinType: document.querySelector(scrollContailerClass).getElementsByClassName
      .transform
      ? "transform"
      : "fixed"
  });
  
  // ------------------------------------------------------------
  // Doors
  // ------------------------------------------------------------
  
  const EASE_DEFAULT = 'power1.inOut';
  
  function openDoorSide ({
    elem, x, scrollTrigger, ease = EASE_DEFAULT
  }) {
    gsap.fromTo(
      elem,
      { x: 0 }, 
      { x, ease, scrollTrigger },
    );
  }
  
  function closeDoors ({ scrollTrigger, ease = EASE_DEFAULT }) {
    gsap.to(".door-left", {
      x: 0,
      ease,
      immediateRender: false,
      scrollTrigger,
    });

    gsap.to(".door-right", {
      x: 0,
      ease,
      immediateRender: false,
      scrollTrigger,
    });
  }

  // ------------------------------------------------------------
  // Scroll triggers
  // ------------------------------------------------------------

  const ScrollTriggerHomeIn = {
    trigger: ".home-in",
    scroller: scrollContailerClass,
    start: "top bottom",
    end: "bottom top",
    markers: true,
    scrub: true,
    invalidateOnRefresh: true,
    onEnter: () => {
      console.log('home enter')
      showContent(contentHome);
    },
    onLeaveBack: () => {
      hideContent(contentHome);
    },
  }
  
  const ScrollTriggerHomeOut = {
    trigger: ".home-out",
    scroller: scrollContailerClass,
    start: "top bottom",
    end: "bottom top",
    markers: true,
    scrub: true,
    invalidateOnRefresh: true,
    onLeave: () => {
      hideContent(contentHome);
      addRandomImage();
    },
    onEnterBack: () => {
      showContent(contentHome);
    }
  }
  
  const ScrollTriggerImageIn = {
    trigger: ".image-in",
    scroller: scrollContailerClass,
    start: "top bottom",
    end: "bottom top",
    markers: true,
    scrub: true,
    invalidateOnRefresh: true,
    onEnter: () => {
      showContent(contentImage);
    },
    onLeaveBack: () => {
      hideContent(contentImage);
    },
  }
  
  const ScrollTriggerImageOut = {
    trigger: ".image-out",
    scroller: scrollContailerClass,
    start: "top bottom",
    end: "bottom top",
    markers: true,
    scrub: true,
    invalidateOnRefresh: true,
    onLeave: () => {
      hideContent(contentImage);
    },
    onEnterBack: () => {
      showContent(contentImage);
    },
  }
  
  // ------------------------------------------------------------
  // Home
  // ------------------------------------------------------------
  
  openDoorSide({
    elem: '.door-left',
    x: () => `${-contentHome.offsetWidth / 2}px`,
    scrollTrigger: ScrollTriggerHomeIn,
  })
  
  openDoorSide({
    elem: '.door-right',
    x: () => `${contentHome.offsetWidth / 2}px`,
    scrollTrigger: ScrollTriggerHomeIn,
  })

  // Closing doors
  
  closeDoors({ scrollTrigger: ScrollTriggerHomeOut })
  
  // ------------------------------------------------------------
  // Image
  // ------------------------------------------------------------
  
  openDoorSide({
    elem: '.door-left',
    x: () => `${-currentImage.width / 2}px`,
    scrollTrigger: ScrollTriggerImageIn,
  })
  
  openDoorSide({
    elem: '.door-right',
    x: () => `${currentImage.width / 2}px`,
    scrollTrigger: ScrollTriggerImageIn,
  })

  // Closing doors
  
  closeDoors({ scrollTrigger: ScrollTriggerImageOut })
  
  // ------------------------------------------------------------
  // Scroll Trigger events
  // ------------------------------------------------------------

  ScrollTrigger.addEventListener("refresh", () => locoScroll.update());
  ScrollTrigger.refresh();
})();

              
            
!
999px

Console