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

              
                <header>
  <div class="container header-container">
    <div class="d-flex justify-content-between">
      <div>logo</div>
      <div>
        <a href="#">nav item</a>
        <a href="#">nav item</a>
        <a href="#">nav item</a>
        <a href="#">nav item</a>
        <a href="#">nav item</a>
      </div>
    </div>
  </div>
</header>
<main class="container">
  <div>
    <h1>Welcome to Page</h1>
  </div>
  <div class="dummmy-placeholder">
    <h2>this is just a dummy div to create some space to scroll<h2>
  </div>

  <div class="group">

    <div class="part-one" data-lottie-path="https://assets.codepen.io/35984/tapered_hello.json">
      <div class="row">
        <div class="col-6">
          <h2>
            Hello here is some lottie animation
          </h2>
        </div>
        <div class="col-6">
          <div class="lottie-anim">
            <div class="lottie-target"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="part-two">

      <div class="img">
        <img src="https://source.unsplash.com/user/erondu/1600x1300" class="img-fluid">
      </div>
      <div class="part-two-content">
        <div class="row">
          <div class="col-6">
            <h2 class="part-two-title">This could be a title thing</h2>
          </div>
          <div class="col-6">
            <p>Some other Text here.</p>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="group">

    <div class="part-one" data-lottie-path="https://assets.codepen.io/35984/tapered_hello.json">
      <div class="row">
        <div class="col-6">
          <h2>
            Hello here is some lottie animation
          </h2>
        </div>
        <div class="col-6">
          <div class="lottie-anim">
            <div class="lottie-target"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="part-two">

      <div class="img">
        <img src="https://source.unsplash.com/user/erondu/1600x1300" class="img-fluid">
      </div>
      <div class="part-two-content">
        <div class="row">
          <div class="col-6">
            <h2 class="part-two-title">This could be a title thing</h2>
          </div>
          <div class="col-6">
            <p>Some other Text here.</p>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="group">

    <div class="part-one" data-lottie-path="https://assets.codepen.io/35984/tapered_hello.json">
      <div class="row">
        <div class="col-6">
          <h2>
            Hello here is some lottie animation
          </h2>
        </div>
        <div class="col-6">
          <div class="lottie-anim">
            <div class="lottie-target"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="part-two">

      <div class="img">
        <img src="https://source.unsplash.com/user/erondu/1600x1300" class="img-fluid">
      </div>
      <div class="part-two-content">
        <div class="row">
          <div class="col-6">
            <h2 class="part-two-title">This could be a title thing</h2>
          </div>
          <div class="col-6">
            <p>Some other Text here.</p>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="dummmy-placeholder">
    <h2>this is just a dummy div to create some space to scroll<h2>
  </div>

  <div class="dummmy-placeholder">
    <h2>this is just a dummy div to create some space to scroll<h2>
  </div>
  <div class="dummmy-placeholder">
    <h2>this is just a dummy div to create some space to scroll<h2>
  </div>
</main>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Signika+Negative:300,400&display=swap");

body {
  font-family: "Signika Negative", sans-serif;
  font-weight: 300;
  margin: 0;
  padding: 0;
}

header {
  position: sticky;
  background: white;
  top: 0;
  z-index: 999;
}

.header-container {
  width: 100%;
  max-width: 1920px;
  padding: 10px 60px;
}

// DUMMY

.dummmy-placeholder {
  height: 70vh;
  padding: 60px 40px;
  background: #f3f3f3;
  margin-bottom: 30px;
}

// PART ONE

.part-one {
  padding-block: 4rem;
  position: relative;
  z-index: -1;
}

.lottie-target {
  aspect-ratio: 2/1;
  border: 1px dashed #e1e1e1;
  min-height: 80px;
}

// PART TWO

.part-two {
  display: grid;
  grid-template-areas: "img";
  background: #f3f3f3;
}

.part-two-content,
.img {
  grid-area: img;
}

.part-two-content {
  padding: 30px 40px;
  background: rgba(#fff, 0.5);
  align-self: start;
}

.part-two-title {
  background: rgba(blue, 0.25);
}

              
            
!

JS

              
                function LottieScrollTrigger(vars) {
  let playhead = { frame: 0 },
    target = gsap.utils.toArray(vars.target)[0],
    speeds = { slow: "+=2000", medium: "+=1000", fast: "+=500" },
    st = {
      trigger: target,
      pin: true,
      start: "top top",
      end: speeds[vars.speed] || "+=1000",
      scrub: 1
    },
    ctx = gsap.context && gsap.context(),
    animation = lottie.loadAnimation({
      container: target,
      renderer: vars.renderer || "svg",
      loop: false,
      autoplay: false,
      path: vars.path,
      rendererSettings: vars.rendererSettings || {
        preserveAspectRatio: "xMidYMid slice"
      }
    });
  for (let p in vars) {
    // let users override the ScrollTrigger defaults
    st[p] = vars[p];
  }
  animation.addEventListener("DOMLoaded", function () {
    let createTween = function () {
      animation.frameTween = gsap.to(playhead, {
        frame: animation.totalFrames - 1,
        ease: "none",
        onUpdate: () => animation.goToAndStop(playhead.frame, true),
        scrollTrigger: st
      });
      return () => animation.destroy && animation.destroy();
    };
    ctx && ctx.add ? ctx.add(createTween) : createTween();
    // in case there are any other ScrollTriggers on the page and the loading of this Lottie asset caused layout changes
    ScrollTrigger.sort();
    ScrollTrigger.refresh();
  });
  return animation;
}

// grab all this projects
const groups = gsap.utils.toArray(".group");
var scrub = 1;
var debug = true;

groups.forEach((group, i) => {
  var partOne = group.querySelector(".part-one");
  var partTwo = group.querySelector(".part-two");

  var lottiePath = gsap.getProperty(partOne, "data-lottie-path");
  var lottieTarget = group.querySelector(".lottie-target");

  var starTrigger = group.querySelector(".part-two-title");
  var endTrigger = partTwo;

  var lottieScroller = LottieScrollTrigger({
    target: lottieTarget,
    path: lottiePath,
    trigger: starTrigger,
    start: "top bottom",
    endTrigger: endTrigger,
    end: "bottom center",
    //  end: () => {
    //   return (
    //    "top center+=" + gsap.getProperty(lottieTarget, "height") / 2 + "px"
    //  );
    // },
    pin: false,
    scrub: scrub,
    markers: debug
  });

  // Part One get Sticky
  ScrollTrigger.create({
    trigger: partOne,
    start: () => `center center`,
    endTrigger: partTwo,
    end: "bottom bottom",
    pinSpacing: false,
    pin: true,
    scrub: scrub
  });

  // Part Two Parallax Animation with scroll
  ScrollTrigger.create({
    trigger: partTwo,
    start: `top bottom`,
    end: "top top",
    animation: gsap.from(partTwo, {
      y: "50"
    }),
    pinSpacing: false,
    // pin: true,
    scrub: scrub
  });
});

              
            
!
999px

Console