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

              
                <section class="container one"></section>
    <section class="container two"></section>
    <section class="container three"></section>
    <section id="main" class="container four">
      <div class="content">
        <h2>Measurement that drives business outcomes</h2>

        <div class="slider">
          <div class="slider-nav">
            <a href="#slide-1" class="nav-item"></a>
            <a href="#slide-2" class="nav-item"></a>
            <a href="#slide-3" class="nav-item"></a>
            <div class="nav-arrow"></div>
          </div>
          <div class="slider-wrap">
            <div class="slider-items">
              <div class="item-slider" id="slide-1">
                <h3>
                  Tying campaings to real-time sales data provides proof of
                  efficient, effective spending and key insights for future
                  planning
                </h3>
              </div>
              <div class="item-slider" id="slide-2">
                <h3>
                  Spend your campaing dollars that are directly tied to sales
                  and optimize along the way
                </h3>
              </div>
              <div class="item-slider" id="slide-3">
                <h3>
                  Tying campaings to real-time sales data provides proof of
                  efficient, effective spending and key insights for future
                  planning
                </h3>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
    <div class="container five"></div>
    <div class="container six"></div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

.container {
  width: 100%;
  height: auto;
  padding: 40px;
  position: relative;
  box-sizing: border-box;
}

#main {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 80vh;
  width: 80vh;
}

h2 {
  text-align: center;
  max-width: 300px;
  margin: 0 auto 40px;
}

.one {
  height: 300px;
  background-color: aqua;
}

.two {
  height: 200px;
  background-color: blue;
}

.three {
  height: 100px;
  background-color: red;
}

.four {
  background-color: skyblue;
  /* padding-left: 0;
  padding-right: 0;
  padding-bottom: 0; */
  overflow: hidden;
  /* height: 600px; */
}

.five {
  height: 200px;
  background-color: yellow;
}

.six {
  height: 100px;
  background-color: purple;
}

.slider {
  width: 100%;
  height: 100%;
  position: relative;
  max-height: 380px;
  max-width: 820px;
  /* border-radius: 60px; */
}
.slider-wrap {
  overflow: hidden;
  height: 100%;
}
.slider-items {
  margin: 0 auto;
  /* width: 500%; */
  height: 100%;

  position: relative;
  /* overflow: hidden; */
  border-radius: 60px;
  display: flex;

  flex-wrap: nowrap;
}

.item-slider {
  /* position: absolute; */
  display: flex;
  flex: 1 0 100%;
  padding: 20px;
  height: 100%;
  width: 100%;
  /* margin: 0 auto; */
  background-color: blue;
}

h3 {
  color: wheat;
}

/* .item-slider:nth-child(2) {
  background-color: brown;
}

.item-slider:nth-child(3) {
  background-color: orange;
} */

.slider-nav {
  position: absolute;
  width: 100%;
  bottom: 40px;
  z-index: 1;
  gap: 10px;
  display: flex;

  justify-content: center;
}

.nav-item {
  width: 8px;
  height: 8px;
  border: 1px solid white;
  border-radius: 50%;
  background-color: transparent;
  cursor: pointer;
  transition: all 0.3s ease;
  display: block;
}

.nav-item.active {
  background-color: white;
}

.nav-arrow {
  width: 16px;
  height: 8px;
  background-color: #fff;
}

@media screen and (min-width: 768px) {
  .slider-nav {
    flex-direction: column;
    align-items: center;
    bottom: auto;
    right: -40px;
    width: auto;
    height: 100%;
  }

  .slider-items {
    flex-direction: column;
  }

  /* .item-slider {
    position: absolute;
  } */

  .nav-arrow {
    transform: rotate(90deg);
  }
}

              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

let mm = gsap.matchMedia();
let mainSection = document.querySelector("#main");
let items = gsap.utils.toArray(".item-slider");

let nav = document.querySelector(".slider-nav");
let dots = gsap.utils.toArray(".nav-item");

let tl = gsap.timeline({
  scrollTrigger: {
    trigger: mainSection,
    start: "center center",
    pin: true,
    scrub: 2,
    end: "+=" + innerHeight,
    markers: true,
  },
});

// Mobile
mm.add("(max-width: 767px)", () => {
  let scrollTween = gsap.to(items, {
    xPercent: -100 * (items.length - 1),
    ease: "none",
    scrollTrigger: {
      trigger: ".slider-wrap",
      start: "top top",
      scrub: 0.1,
      end: "+=6000",
      // markers: true,
    },
  });

  items.forEach((item, i) => {
    ScrollTrigger.create({
      trigger: item,
      containerAnimation: scrollTween,
      start: "top top",
      end: i === items.length - 1 ? "right right" : "right 30%",
      onToggle: (self) => {
        console.log("first");
        gsap.to(dots[i], {
          background: self.isActive ? "white" : "transparent",
        });
      },
      // markers: true,
    });
  });
});

// Desktop
mm.add("(min-width: 768px)", () => {
  console.log(dots);

  items.forEach((item, i) => {
    ScrollTrigger.create({
      trigger: item,
      start: "top center",
      // animation: tl,
      markers: {
        startColor: "blue",
        endColor: "yellow",
        fontSize: "18px",
        fontWeight: "bold",
        indent: 20,
      },
      scrub: 1,

      end: "bottom center",
      onEnter: () => {
        console.log("enter", i);
        // lt.to(dots[i], {
        //   background: self.isActive ? "white" : "transparent",
        // });
      },

      onToggle: (self) => {
        console.log(self);
        gsap.to(dots[i], {
          background: self.isActive ? "white" : "transparent",
        });
      },
      onLeave: () => {
        gsap.to(dots[i], {
          background: "transparent",
        });
      },
    });
  });
});

              
            
!
999px

Console