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

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="wrapper">

    <section class="section">

        <a href="" class="img-gradient">
          <div class="section--text">01</div>
          <img src="https://picsum.photos/600/800?random=1">
        </a>

    </section>

    <section class="section">

        <a href="" class="img-gradient">
          <div class="section--text">02</div>
          <img src="https://picsum.photos/600/800?random=2">
        </a>

    </section>

    <section class="section">

        <a href="" class="img-gradient">
          <div class="section--text">03</div>
          <img src="https://picsum.photos/600/800?random=3">
        </a>

    </section>

    <section class="section">

        <a href="" class="img-gradient">
          <div class="section--text">04</div>
          <img src="https://picsum.photos/600/800?random=4">
        </a>

    </section>

    <section class="section">

        <a href="" class="img-gradient">
          <div class="section--text">05</div>
          <img src="https://picsum.photos/600/800?random=5">
        </a>

    </section>

    <section class="section">

        <a href="" class="img-gradient">
          <div class="section--text">06</div>
          <img src="https://picsum.photos/600/800?random=6">
        </a>

    </section>

    <section class="section">

        <a href="" class="img-gradient">
          <div class="section--text">07</div>
          <img src="https://picsum.photos/600/800?random=7">
        </a>

    </section>

    <section class="section">

        <a href="" class="img-gradient">
          <div class="section--text">08</div>
          <img src="https://picsum.photos/600/800?random=8">
        </a>
      
    </section>

    <section class="section">

        <a href="" class="img-gradient">
          <div class="section--text">09</div>
          <img src="https://picsum.photos/600/800?random=9">
        </a>

    </section>

    <section class="section">

        <a href="" class="img-gradient">
          <div class="section--text">10</div>
          <img src="https://picsum.photos/600/800?random=10">
        </a>

    </section>

    <section class="section">

        <a href="" class="img-gradient">
          <div class="section--text">11</div>
          <img src="https://picsum.photos/600/800?random=11">
        </a>

    </section>

</div>

<div class="navi navi--prev">Prev</div>
<div class="navi navi--next">Next</div>
              
            
!

CSS

              
                ::-webkit-scrollbar {
  display: none;
}

@import url("https://fonts.googleapis.com/css2?family=Montserrat:[email protected];500;700;800;900&display=swap");

body {
  font-family: "Monserrat", sans-serif, Arial;
}
.wrapper {
  display: flex;
  flex-wrap: nowrap;
  position: fixed;
}

.section {
  display: flex;
  flex-shrink: 0;
  height: 100vh;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
  width: 33.33vw;
  font-size: 30px;

  img {
    height: 100vh;
  }

  .img-gradient {
    display: inline-block;
    height: 100%;

    &:after {
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      display: inline-block;
      background: -moz-linear-gradient(
        top,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0) 50%,
        rgba(0, 0, 0, 1) 100%
      ); /* FF3.6-15 */
      background: -webkit-linear-gradient(
        top,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0) 50%,
        rgba(0, 0, 0, 1) 100%
      ); /* Chrome10-25,Safari5.1-6 */
      background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0) 50%,
        rgba(0, 0, 0, 1) 100%
      ); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
      filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#000000',GradientType=0 ); /* IE6-9 */
    }
  }

  &--text {
    position: absolute;
    bottom: 15%;
    left: 20%;
    width: 100%;
    z-index: 99;
    color: #fff;
    font-size: 200px;
    opacity: 0.5;

    h2 {
      font-weight: 700;
      letter-spacing: -0.05em;

      span {
        opacity: 0.75;
        font-weight: 400;
      }
    }

    p {
      font-size: 14px;
      opacity: 0;
    }
  }
}

.navi {
  position: fixed;
  bottom: 2%;
  border-radius: 50%;
  color: #fff;
  width: 45px;
  height: 45px;
  cursor: pointer;
  z-index: 4;
  opacity: 1;
}

.navi--prev {
  left: 2.188rem;
}

.navi--next {
  right: 2.188rem;
}

              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);
gsap.registerPlugin(ScrollToPlugin);

/* SCROLL TRIGGER SCROLLER */

var scroller = document.querySelector(".wrapper");

var sections = document.querySelectorAll(".section");
var numSections = sections.length;
var sectionWidth = Math.floor(scroller.offsetWidth / numSections);

let scrollWidth;
function createScroller() {
  scrollWidth = scroller.offsetWidth - innerWidth;
  ScrollTrigger.addEventListener("refreshInit", () => {
    scrollWidth = scroller.offsetWidth - innerWidth;
    gsap.set(document.body, {height: scrollWidth + innerHeight});
  });
}


createScroller();

scroll_tl = gsap.timeline();

var triggerAmount = 0;

scroll_tl.to(scroller, {
    x: () => -scrollWidth,
    ease: "none",
    scrollTrigger: {
      start: 0,
      end: "bottom bottom",
      scrub: 0.75,
      invalidateOnRefresh: true,
      onUpdate: trigger => triggerAmount = trigger.progress
      //onUpdate: trigger => console.log(trigger.progress)
    }
});

/* NAV BUTTONS */

// use to position scroller
let scroll_to = 0;
// set width of scroller minus width of screen to get moveable width
let maxScrollerWidth = scroller.offsetWidth - innerWidth;


function slideAnim(e) {
  
  e.preventDefault();
  
  // NAVIGATION BUTTONS. 
  // Should move by +/- three sections
  
  // First, check to see if we've used the mousewheel
  // If we have, then we need to update the scroll_to position
  // so it matches how far we might have moved with scroll trigger
  // multiply that by total moveable width to get approximate px width
  // we can then add or subtract that from scroll_to
  triggerMoved = Math.floor(triggerAmount * scrollWidth);
  
  // NEXT
  if( $(this).hasClass("navi--next") ){
    
    // check to see if we can move three sections forward (right)
    if ((scroll_to + innerWidth) < maxScrollerWidth) {
      
      // scroll_to + screen width is less than overall moveable width
      // so lets set scroll_to = trigger position + screenwidth
      scroll_to = innerWidth + triggerMoved;
      
    } else {
      
      // scroll_to + screen width is more than overall moveable width
      // so we can just go to right to the end
      scroll_to = maxScrollerWidth;
    }
    
  }
  
  // PREV
  if( $(this).hasClass("navi--prev") ){

    // check to see if we can move three sections back (left) 
    if ((triggerMoved - innerWidth) > 0 ) {
      
      // scrollTrigger position - screen width is more than 0
      // so we can set scroll_to to position - screen width
      scroll_to = (triggerMoved - innerWidth);

    } else {
      
      // scrollTrigger position - screen width would be less than 0
      // so we can just set scroll_to 0 and we're done
      scroll_to = 0;
    }

  }

  nav_tl = gsap.timeline();
  
  nav_tl.to(window, {
    duration: 1.5, 
    ease:"power4.out",
    scrollTo: scroll_to
  });
  
}
  
document.querySelector(".navi--prev").addEventListener("click", slideAnim);
document.querySelector(".navi--next").addEventListener("click", slideAnim);
              
            
!
999px

Console