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

              
                <div class="wrapper">

  <section class="vertical">
    <h2>Vertical Section</h2>
  </section>
  <section class="horizontal">
    <div class="horizontal__container content-container">

      <div class="horizontal__scroll">
        <h2>Lorem Ipsum</h2>
        <div class="horizontal__list">
          <div class="horizontal__item">
            <div class="numbers" id="number-01">0,0</div>
            <h2>Counter Description</h2>
          </div>
          <div class="horizontal__item">
            <div class="numbers" id="number-02">0,0</div>
            <h2>Counter Description</h2>
          </div>
          <div class="horizontal__item">
            <div class="numbers" id="number-03">0,0</div>
            <h2>Counter Description</h2>
          </div>
          <div class="horizontal__item">
            <div class="numbers" id="number-04">0,0</div>
            <h2>Counter Description</h2>
          </div>
        </div>
      </div>
    </div>
  </section>

  <div class="drag-proxy"></div>

  <section class="vertical">
    <h2>Vertical Section</h2>
  </section>

  <footer>Footer Section</footer>

</div>
              
            
!

CSS

              
                body {
  margin: 0;
  overflow-x: hidden;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 20px;
}

.horizontal {
  padding: 60px 20px 120px;
  box-sizing: border-box;
}

.horizontal__container {
  margin: 0 auto;
  width: 100%;
  position: relative;
}

.horizontal__list {
  display: flex;
  padding-left: calc(50vw - 600px / 2);
}

.horizontal__item {
  margin-left: 10vw;
  min-width: 60vw;
  height: 80vh;
  background: #EEE;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  box-sizing: border-box;
}

.horizontal__item h2 {
  width: 100%;
  text-align: center;
}

.horizontal__item:first-of-type {
  margin-left: 0;
}

.numbers {
  width: 100%;
  text-align: center;
  margin-bottom: 3rem;
  font-size: 4rem;
}

.vertical,
footer {
  width: 100%;
  height: 20vh;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
}

.vertical {
  background: cyan;
}

footer {
  background: black;
}

.drag-proxy {
  visibility: hidden;
  position: absolute;
}

html,
body {
  scroll-behavior: auto !important;
}

              
            
!

JS

              
                console.clear(); // Start with a clean console on refesh 
//credits to akapowl: https://codepen.io/akapowl/pen/qBXOMme/5351d83e2b4241bfe3407ef6113e1f51 and mikel: https://codepen.io/mikeK/pen/zYoEEox
gsap.registerPlugin(ScrollTrigger, Draggable);

const sections = gsap.utils.toArray(".horizontal__item");
let maxWidth = 0;

const getMaxWidth = () => {
    maxWidth = 0;
    sections.forEach((section) => {
        maxWidth += section.offsetWidth;
        maxWidth += gsap.getProperty(section, "marginLeft");
    });

    maxWidth += gsap.getProperty(".horizontal", "paddingLeft");
    maxWidth += gsap.getProperty(".horizontal__list", "paddingLeft");
    // after the calculations above the right side of the last image  should be flush against the right side of the window
    // but with the scrollbar sitting on top of it, so you might want to add some space
    // if you want the white margin/padding to be visible
    maxWidth += 700;

    return maxWidth;
};

getMaxWidth();
ScrollTrigger.addEventListener("refreshInit", getMaxWidth);

gsap.set(".horizontal__item h2", {
    y: 50,
    opacity: 0
});

let scrollTween = gsap.to(sections, {
    x: () => `-${maxWidth - window.innerWidth}`,
    ease: "none"
});

let horizontalScroll = ScrollTrigger.create({
    animation: scrollTween,
    trigger: ".horizontal",
    pin: ".wrapper",
    scrub: 0.5,
    end: () => `+=${maxWidth}`,
    invalidateOnRefresh: true
});

//COUNT UP
let numbers = document.querySelectorAll(".numbers");
console.warn(numbers);
var startCount = 0,
    num = {
        var: startCount
    };

let tlNumber1 = gsap.timeline({
        scrollTrigger: {
            trigger: "#number-01",
            containerAnimation: scrollTween,
            start: "50% 50%",
            markers: true,
            scrub: true,
            end: "70% 50%",
            toggleActions: "restart none none reverse"
        }
    })
    .to("#number-01", {
        textContent: "100.5",
        duration: 1,
        snap: { textContent: 0.1 },
        ease: "none",
        // onUpdate: (a,b,c) => {
        //   changeNumber(a,b,c)
        // }
      onUpdate: function() {
        const replaceDot = this._targets[0].textContent.replace('.', ',');
        document.querySelector('#number-01').innerText =replaceDot;
},
    });
    
let tlNumber2 = gsap.timeline({
        scrollTrigger: {
            trigger: "#number-02",
            containerAnimation: scrollTween,
            start: "0% 50%",
            markers: true,
            scrub: true,
            end: "70% 50%",
            toggleActions: "restart none none reverse"
        }
    })
    .to("#number-02", {
        textContent: "200.5",
        snap: { textContent: 0.1 },
        duration: 1,
        ease: "none",
        onUpdate: changeNumber
    });
    
let tlNumber3 = gsap.timeline({
        scrollTrigger: {
            trigger: "#number-03",
            containerAnimation: scrollTween,
            start: "0% 50%",
            markers: true,
            scrub: true,
            end: "70% 50%",
            toggleActions: "restart none none reverse"
        }
    })
    .to("#number-03", {
        textContent: "300,5",
        snap: { textContent: 1 },
        duration: 1,
        ease: "none",
        onUpdate: changeNumber
    });
    
let tlNumber4 = gsap.timeline({
        scrollTrigger: {
            trigger: "#number-04",
            containerAnimation: scrollTween,
            start: "0% 50%",
            markers: true,
            scrub: true,
            end: "50% 50%",
            toggleActions: "restart none none reverse"
        }
    })
    .to("#number-04", {
        textContent: "400,5",
        snap: { textContent: 1 },


        duration: 1,
        ease: "none",
        onUpdate: changeNumber
    });     


function changeNumber(a, b, c) {
    // numbers.innerHTML = (num.var).toFixed(1);
  console.warn(a, b, c);
}

//HEADING ANIMATION
sections.forEach((sct, i) => {

    const heading = sct.querySelector(".horizontal__item h2");

    if (heading) {

        if (i === 0) {

            gsap.to(heading, {
                duration: 1,
                y: 0,
                opacity: 1,
                scrollTrigger: {
                    trigger: ".horizontal",
                    start: "top top",
                    markers: false,
                    toggleActions: "play pause resume reset"
                }
            });

        } else {

            gsap.to(heading, {
                duration: 1,
                y: 0,
                opacity: 1,
                scrollTrigger: {
                    trigger: heading,
                    pinnedContainer: ".wrapper",
                    containerAnimation: scrollTween,
                    start: "50% 100%",
                    end: "100% 0%",
                    markers: false,
                    toggleActions: "play pause resume reset"
                }
            });

        }



    }

});

//MAKE IT DRAGGABLE
var dragRatio = maxWidth / (maxWidth - window.innerWidth);

var drag = Draggable.create(".drag-proxy", {
    trigger: ".horizontal",
    type: "x",
    inertia: false,
    allowContextMenu: true,
    onPress() {
        this.startScroll = horizontalScroll.scroll();
    },
    onDrag() {
        horizontalScroll.scroll(
            this.startScroll - (this.x - this.startX) * dragRatio
        );
    },
    onThrowUpdate() {
        horizontalScroll.scroll(
            this.startScroll - (this.x - this.startX) * dragRatio
        );
    }
})[0];
              
            
!
999px

Console