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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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'>
  <h1>The Simpsons</h1>
  <div class="cards">
    <button class="btn prev"><span>Prev</span></button>
    <button class="btn next"><span>Next</span></button>
    <div class="card card00">
      <div class="content">
        <div class="circle"></div>
        <img src='https://assets.codepen.io/489403/swsb_character_fact_homer_550x960.png' />
        <h2 class="card-title">Homer Simpson</h2>
        <p class="card-subtitle">"Whatever, I'll be at Moe's."</p>
      </div>
    </div>
    <div class="card card01">
      <div class="content">
        <div class="circle"></div>
        <img src='https://3.bp.blogspot.com/-Hdtlj-R6Hf8/VzzWFQpDJ6I/AAAAAAAAAxc/Oc59XlUjFRsVRd7fqiHCmPiCBZv43c_4QCLcB/s320/swsb_character_fact_disco_550x960.png' />
        <h2 class="card-title">Disco Stu</h2>
        <p class="card-subtitle">“Disco Stu wishes he'd gone as Marilyn McCoo.”</p>

      </div>
    </div>
    <div class="card card02">
      <div class="content">
        <div class="circle"></div>
        <img src='https://assets.codepen.io/489403/swsb_character_fact_duffman_550x960.png' />
        <h2 class="card-title">Duffman</h2>
        <p class="card-subtitle">"Duffman can still party and dance!"</p>

      </div>
    </div>
    <div class="card card03">
      <div class="content">
        <div class="circle"></div>
        <img src='https://assets.codepen.io/489403/swsb_character_fact_barney_550x960.png' />
        <h2 class="card-title">Barney Gumble</h2>
        <p class="card-subtitle">“Don't cry for me, I'm already dead.”</p>

      </div>
    </div>
    <div class="card card04">
      <div class="content">
        <div class="circle"></div>
        <img src='https://assets.codepen.io/489403/swsb_character_fact_bart_550x960.png' />
        <h2 class="card-title">Bart Simpson</h2>
        <p class="card-subtitle">"I'm Bart Simpson, Who the Hell are You?"</p>

      </div>
    </div>
    <div class="card card05">
      <div class="content">
        <div class="circle"></div>
        <img src='https://assets.codepen.io/489403/swsb_character_fact_lisa_550x960.png' />
        <h2 class="card-title">Lisa Simpson</h2>
        <p class="card-subtitle">"If anyone wants me, I'll be in my room."</p>

      </div>
    </div>
    <div class="card card06">
      <div class="content">
        <div class="circle"></div>
        <img src='https://assets.codepen.io/489403/swsb_character_fact_maggie_550x960.png' />
        <h2 class="card-title">Maggie Simpson</h2>
        <p class="card-subtitle">"suck, suck, suck"</p>

      </div>
    </div>
    <div class="card card07">
      <div class="content">
        <div class="circle"></div>
        <img src='https://assets.codepen.io/489403/swsb_character_fact_marge_550x960.png' />
        <h2 class="card-title">Marge Simpson</h2>
        <p class="card-subtitle">"You have no idea what it's like, being married to you."</p>

      </div>
    </div>
    <div class="card card08">
      <div class="content">
        <div class="circle"></div>
        <img src='https://assets.codepen.io/489403/swsb_character_fact_nedflanders_550x960.png' />
        <h2 class="card-title">Ned Flanders</h2>
        <p class="card-subtitle">"What can I ding-dong-diddily-do for you?"</p>

      </div>
    </div>
  </div>

</div>
              
            
!

CSS

              
                .wrapper {
  width: 70%;
  margin: 0 auto;
}

h1 {
  font-family: "Simpsonfont";
  font-size: 60px;
  text-align: center;
  margin-top: 10vh;
}

body {
  margin: 0;
  transition: background-color 0.4s linear;
}

img {
  height: 200px;
  z-index: 20;
}

.card00 {
  background: #b3cc7c;
}

.card01 {
  background: #aa935f;
  color: white;
}

.card02 {
  background: #c00503;
}

.card03 {
  background: #1460c4;
  color: white;
}

.card04 {
  background: #fb0a02;
}

.card05 {
  background: #33b2ce;
  color: white;
}

.card06 {
  background: #fcc302;
}

.card07 {
  background: #464e46;
  color: white;
}

.card08 {
  background: #fb8704;
}

.cards {
  visibility: hidden;
  opacity: 0;
  height: 100vh;
  position: relative;
}

.circle {
  height: 150px;
  width: 150px;
  border-radius: 50%;
  background: red;
  z-index: -1;
  position: absolute;
  top: 1vh;
  left: 43.5vw;
  background-image: url("https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fi.pinimg.com%2Foriginals%2F7d%2Fa6%2F96%2F7da696f1987d39249d42946f331ccc1b.jpg&f=1&nofb=1");
  background-size: cover;
  border: 2px solid;
  animation: move1 5s linear 0s infinite alternate;
}

@keyframes move1 {
  0% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(-5px);
  }
  100% {
    transform: translate(5px, 0);
  }
}

.card {
  text-align: center;
  position: fixed;
  top: 25vh;
  bottom: 0;
  left: 0;
  right: 0;
  background: transparent;
}

p {
  font-family: "Open Sans";
  font-size: 20px;
  text-transform: lowercase;
  font-style: italic;
}

button.btn {
  display: block;
  width: 70px;
  height: 70px;
  background-color: rgba(0, 0, 0, 0.2);
  border: none;
  color: rgba(255, 255, 255, 0.7);
  border-radius: 100%;
  transition: all 0.3s linear;
  overflow: hidden;

  position: absolute;
  top: 20vh;
  z-index: 1;
}
button.btn.next {
  left: auto;
  right: 0;
}
button.btn span {
  display: none;
}
button.btn:hover,
button.btn:focus,
button.btn:active {
  outline: none;
  background-color: rgba(0, 0, 0, 0.4);
  color: rgba(255, 255, 255, 1);
  border-radius: 100%;
  cursor: pointer;
}
button.btn:before {
  content: "\2039";
  display: block;
  position: absolute;
  top: -13px;
  font-size: 70px;
  font-weight: 300;
}
button.btn.prev:before {
  content: "\2039";
  left: 23px;
}
button.btn.next:before {
  content: "\203a";
  left: 28px;
}

@font-face {
  font-family: "Simpsonfont";
  src: url("https://assets.codepen.io/489403/Simpsonfont.ttf");
}
.card-title {
  font-family: "Simpsonfont";
  font-size: 30px;
}

.dots {
  position: absolute;
  left: 0;
  right: 0;
  top: 58vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dot {
  background-color: rgba(255, 255, 255, 0.2);
  width: 20px;
  height: 20px;
  text-indent: -9999em;
  overflow: hidden;
  border: none;
  border-radius: 100%;
  transition: all 0.3s linear;
  margin: 0 8px;
  cursor: pointer;
}
.dot:focus,
.dot:active,
.dot:hover {
  outline: none;
  background-color: rgba(255, 255, 255, 0.4);
}
.dot.active {
  background-color: rgba(255, 255, 255, 0.4);
}

.spot {
  background-color: rgba(255, 255, 255, 1);
  width: 10px;
  height: 10px;
  border-radius: 10px;
  top: 5px;
  z-index: -1;
  position: absolute;
}

              
            
!

JS

              
                function init() {
  //GSDevTools.create();

  gsap.set(".cards", { autoAlpha: 1 });
  gsap.set(".card", { x: "-100%" });

  let currentStep = 0;
  const totalSlides = document.querySelectorAll(".card").length;

  const wrapper = gsap.utils.wrap(0, totalSlides);

  createTimelineIn("next", currentStep);

  function createTimelineIn(direction, index) {
    const goPrev = direction === "prev";

    const element = document.querySelector("div.card0" + index);
    const cardClasses = element.className.split(" ");
    const cardClass = cardClasses[1];
    const title = element.querySelector(".card-title");
    const subtitle = element.querySelector(".card-subtitle");
    const button = element.querySelector(".button-container");
    const splitHeadline = new SplitText(title, { type: "words, chars" });
    const chars = splitHeadline.chars;

    const letters = goPrev ? chars.reverse() : chars;

    const tlIn = gsap.timeline({
      defaults: {
        modifiers: {
          x: gsap.utils.unitize(function (x) {
            return goPrev ? Math.abs(x) : x;
          }),

          rotation: gsap.utils.unitize(function (rotation) {
            return goPrev ? -rotation : rotation;
          })
        }
      }
    });
    tlIn
      .fromTo(
        element,
        {
          autoAlpha: 0,
          x: "-100%"
        },
        {
          duration: 0.7,
          x: 0,
          autoAlpha: 1,
          onStart: updateClass,
          onStartParams: [cardClass]
        }
      )
      .from(letters, {
        x: -20,
        y: 30,
        autoAlpha: 0,
        scale: 0.1,
        rotation: "60deg",
        transformOrigin: "0 100% 0",
        stagger: 0.02,
        duration: 0.25,
        ease: Power1.out
      })
      .from(
        [subtitle, button],
        {
          duration: 0.2,
          x: -20,
          autoAlpha: 0,
          stagger: 0.1
        },
        "-=0.1"
      );

    return tlIn;
  }

  function createTimelineOut(direction, index) {
    const goPrev = direction === "prev";
    const element = document.querySelector("div.card0" + index);
    const tlOut = gsap.timeline();
    tlOut.to(element, {
      duration: 0.7,
      x: 250,
      autoAlpha: 0,
      modifiers: {
        x: gsap.utils.unitize(function (x) {
          return goPrev ? -x : x;
        })
      },
      ease: "back.in(2)"
    });
    return tlOut;
  }

  function updateCurrentStep(goToIndex) {
    currentStep = goToIndex;

    document.querySelectorAll(".dot").forEach(function (element, index) {
      element.setAttribute("class", "dot");
      if (index === currentStep) {
        element.classList.add("active");
      }
    });
    positionDot();
  }

  function transition(direction, toIndex) {
    const tlTransition = gsap.timeline({
      onStart: function () {
        updateCurrentStep(toIndex);
      }
    });

    const tlOut = createTimelineOut(direction, currentStep);
    const tlIn = createTimelineIn(direction, toIndex);

    tlTransition.add(tlOut).add(tlIn);

    return tlTransition;
  }

  function isTweening() {
    return gsap.isTweening(".card");
  }

  document.querySelector("button.next").addEventListener("click", function (e) {
    e.preventDefault();

    const nextStep = wrapper(currentStep + 1);

    !isTweening() && transition("next", nextStep);
  });

  document.querySelector("button.prev").addEventListener("click", function (e) {
    e.preventDefault();

    const prevStep = wrapper(currentStep - 1);

    !isTweening() && transition("prev", prevStep);
  });

  function updateClass(cardClass) {
    document.querySelector("body").className = cardClass;
  }

  function createNavigation() {
    const newDiv = document.createElement("div");
    newDiv.setAttribute("class", "dots");

    const spot = document.createElement("div");
    spot.setAttribute("class", "spot");

    for (let index = 0; index < totalSlides; index++) {
      const element = document.createElement("button");
      const text = document.createTextNode(index);
      element.appendChild(text);
      element.setAttribute("class", "dot");
      if (currentStep === index) {
        element.classList.add("active");
      }

      element.addEventListener("click", function () {
        if (!isTweening() && currentStep !== index) {
          const direction = index > currentStep ? "next" : "prev";
          transition(direction, index);
        }
      });
      newDiv.appendChild(element);
    }

    //append to container
    newDiv.appendChild(spot);
    document.querySelector(".cards").appendChild(newDiv);
    positionDot();
  }

  function positionDot() {
    const activeDotX = document.querySelector(".dot.active").offsetLeft;
    console.log(activeDotX);
    const spot = document.querySelector(".spot");
    const spotX = spot.offsetLeft;
    const destinationX = Math.round(activeDotX - spotX + 5);

    const dotTl = gsap.timeline();
    dotTl
      .to(spot, {
        duration: 0.4,
        x: destinationX,
        scale: 2.5,
        ease: "power1.Out"
      })
      .to(spot, {
        duration: 0.2,
        scale: 1,
        ease: "power1.in"
      });
  }

  createNavigation();
}

window.addEventListener("load", function () {
  init();
});

              
            
!
999px

Console