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

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="./index.css" />
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=Oswald:wght@200;300;400;500;600;700&family=Raleway:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Roboto&display=swap"
      rel="stylesheet"
    />
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=Cormorant:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&family=Oswald:wght@200;300;400;500;600;700&family=Raleway:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Roboto&display=swap"
      rel="stylesheet"
    />
    <title>GSAP Tests</title>
  </head>
  <body>
    <div class="team-left-text">
      <h2 class="team-left-text-title">Our team</h2>
      <p class="team-left-text-body">
        The great minds behind the code
      </p>
    </div>
    <div class="gallery">
      <ul class="cards">
        <li>
          <img src="https://pic.onlinewebfonts.com/svg/img_405324.png" class="team-member-img" />
          <div class="team-member-div-text">
            <p class="team-member-text">Marcus Lawrence</p>
            <p class="team-member-sub-text">Communication Lead</p>
          </div>
        </li>
        <li>
          <img src="https://pic.onlinewebfonts.com/svg/img_405324.png" class="team-member-img" />
          <p class="team-member-text">Team Member</p>
          <p class="team-member-sub-text">Software Developer</p>
        </li>
        <li>
          <img src="https://pic.onlinewebfonts.com/svg/img_405324.png" class="team-member-img" />
          <p class="team-member-text">Team Member</p>
          <p class="team-member-sub-text">Software Developer</p>
        </li>
        <li>
          <img src="https://pic.onlinewebfonts.com/svg/img_405324.png" class="team-member-img" />
          <p class="team-member-text">Team Member</p>
          <p class="team-member-sub-text">Software Developer</p>
        </li>
        <li><img src="https://pic.onlinewebfonts.com/svg/img_405324.png" class="team-member-img" /></li>
        <li><img src="https://pic.onlinewebfonts.com/svg/img_405324.png" class="team-member-img" /></li>
        <li><img src="https://pic.onlinewebfonts.com/svg/img_405324.png" class="team-member-img" /></li>
        <li><img src="https://pic.onlinewebfonts.com/svg/img_405324.png" class="team-member-img" />
        <div class="team-member-div-text">
        <p class="team-member-text">Last Element</p>
        <p class="team-member-sub-text">Final Element of List</p>
        </div></li>
      </ul>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/ScrollTrigger.min.js"></script>
    <script src="index.js"></script>
  </body>
</html>

              
            
!

CSS

              
                /* ------------------- TEMPLATE START ---------------------------------*/
* {
  box-sizing: border-box;
}
body {
  background:  #F8F4F1;
  min-height: 100vh;
  padding: 0;
  margin: 0;
}
.gallery {
  position: absolute;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.cards {
  position: absolute;
  width: 14rem;
  height: 18rem;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.cards li {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 14rem;
  height: 18rem;
  text-align: center;
  line-height: 18rem;
  font-size: 2rem;
  font-family: sans-serif;
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 0.8rem;
}

a {
  color: #88ce02;
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ------------------- TEMPLATE END---------------------------------*/

.team-member-img {
  height: 405px;
  width: 250px;
}

.team-member-div-text {
  justify-content: center;
}

.team-member-text {
  position: absolute;
  top: 370px;
  left: 20px;

  font-family: Cormorant;
  font-style: italic;
  font-weight: bold;
  font-size: 32px;
  line-height: 44px;
  /* identical to box height */

  text-align: center;

  color: #5d738c;
}

.team-member-sub-text {
  position: absolute;
  width: 179px;
  height: 21px;
  top: 420px;
  left: 20px;

  font-family: Raleway;
  font-style: normal;
  font-weight: normal;
  font-size: 18px;
  line-height: 21px;
  text-align: center;

  color: #5d738c;
}

.team-left-text {
  position: absolute;
  top: 200px;
  left: 165px;
  background-image: #fff;
}

.team-left-text-title {
  width: 262px;
  height: 42px;
  font-family: Raleway;
  font-style: normal;
  font-weight: 800;
  font-size: 36px;
  line-height: 42px;
  color: #3ac4d2;
}

.team-left-text-body {
  width: 445px;
  height: 56px;
  font-family: Raleway;
  font-style: normal;
  font-weight: 500;
  font-size: 24px;
  line-height: 28px;
  color: #5d738c;
}

              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

let iteration = 0; // gets iterated when we scroll all the way to the end or start and wraps around - allows us to smoothly continue the playhead scrubbing in the correct direction.

const spacing = 0.1, // spacing of the cards (stagger)
  snap = gsap.utils.snap(spacing), // we'll use this to snap the playhead on the seamlessLoop
  cards = gsap.utils.toArray(".cards li"),
  seamlessLoop = buildSeamlessLoop(cards, spacing),
  scrub = gsap.to(seamlessLoop, {
    // we reuse this tween to smoothly scrub the playhead on the seamlessLoop
    totalTime: 0,
    duration: 0.5,
    ease: "power3",
    paused: true,
  }),
  trigger = ScrollTrigger.create({
    start: 0,
    onUpdate(self) {
      if (self.progress === 1 && self.direction > 0 && !self.wrapping) {
        //wrapForward(self);
      } else if (self.progress < 1e-5 && self.direction < 0 && !self.wrapping) {
        //wrapBackward(self);
      } else {
        scrub.vars.totalTime = snap(
          (iteration + self.progress) * seamlessLoop.duration()
        );
        scrub.invalidate().restart(); // to improve performance, we just invalidate and restart the same tween. No need for overwrites or creating a new tween on each update.
        self.wrapping = false;
      }
    },
    end: "+=3000",
    pin: ".gallery",
  });

function wrapForward(trigger) {
  // when the ScrollTrigger reaches the end, loop back to the beginning seamlessly
  iteration++;
  trigger.wrapping = true;
  trigger.scroll(trigger.start + 1);
}

function wrapBackward(trigger) {
  // when the ScrollTrigger reaches the start again (in reverse), loop back to the end seamlessly
  iteration--;
  if (iteration < 0) {
    // to keep the playhead from stopping at the beginning, we jump ahead 10 iterations
    iteration = 9;
    seamlessLoop.totalTime(
      seamlessLoop.totalTime() + seamlessLoop.duration() * 10
    );
    scrub.pause(); // otherwise it may update the totalTime right before the trigger updates, making the starting value different than what we just set above.
  }
  trigger.wrapping = true;
  trigger.scroll(trigger.end - 1);
}

function scrubTo(totalTime) {
  // moves the scroll position to the place that corresponds to the totalTime value of the seamlessLoop, and wraps if necessary.
  let progress =
    (totalTime - seamlessLoop.duration() * iteration) / seamlessLoop.duration();
  if (progress > 1) {
    //wrapForward(trigger);
  } else if (progress < 0) {
    //wrapBackward(trigger);
  } else {
    trigger.scroll(trigger.start + progress * (trigger.end - trigger.start));
  }
}

function buildSeamlessLoop(items, spacing) {
  let overlap = Math.ceil(1 / spacing), // number of EXTRA animations on either side of the start/end to accommodate the seamless looping
    startTime = items.length * spacing + 0.5, // the time on the rawSequence at which we'll start the seamless loop
    loopTime = (items.length + overlap) * spacing + 1, // the spot at the end where we loop back to the startTime
    rawSequence = gsap.timeline({ paused: true }), // this is where all the "real" animations live
    seamlessLoop = gsap.timeline({
      // this merely scrubs the playhead of the rawSequence so that it appears to seamlessly loop
      paused: true,
      repeat: -1, // to accommodate infinite scrolling/looping
      onRepeat() {
        // works around a super rare edge case bug that's fixed GSAP 3.6.1
        this._time === this._dur && (this._tTime += this._dur - 0.01);
      },
    }),
    l = items.length + overlap * 2,
    time = 0,
    i,
    index,
    item;

  // set initial state of items
  gsap.set(items, { xPercent: 400, opacity: 0, scale: 0 });

  // now loop through and create all the animations in a staggered fashion. Remember, we must create EXTRA animations at the end to accommodate the seamless looping.
  for (i = 0; i < l; i++) {
    index = i % items.length;
    item = items[index];
    time = i * spacing;
    rawSequence
      .fromTo(
        item,
        { scale: 0, opacity: 0 },
        {
          scale: 1,
          opacity: 1,
          zIndex: 100,
          duration: 0.5,
          yoyo: true,
          repeat: 1,
          ease: "power1.in",
          immediateRender: false,
        },
        time
      )
      .fromTo(
        item,
        { xPercent: 400 },
        { xPercent: -400, duration: 1, ease: "none", immediateRender: false },
        time
      );
    i <= items.length && seamlessLoop.add("label" + i, time); // we don't really need these, but if you wanted to jump to key spots using labels, here ya go.
  }

  // here's where we set up the scrubbing of the playhead to make it appear seamless.
  rawSequence.time(startTime);
  seamlessLoop
    .to(rawSequence, {
      time: loopTime,
      duration: loopTime - startTime,
      ease: "none",
    })
    .fromTo(
      rawSequence,
      { time: overlap * spacing + 1 },
      {
        time: startTime,
        duration: startTime - (overlap * spacing + 1),
        immediateRender: false,
        ease: "none",
      }
    );
  return seamlessLoop;
}

              
            
!
999px

Console