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

              
                <main id="main">
  <!-- section 01 -->
  <section id="sec-01">1</section>
  <!-- section 02 -->
  <section id="sec-02">2</section>
  <!-- section 03 -->
  <section id="sec-03">3</section>
  <!-- section 04 -->
  <section id="sec-04">4</section>
</main>
<div class="dot-indicator">
  <nav>
    <ul>
      <li class="sec-01"><a id="sec01" index="0" data="#sec-01">&#9679</a></li>
                <li class="sec-02"><a id="sec02" index="1" data="#sec-02">&#9679</a></li>
                <li class="sec-03"><a id="sec03" index="2" data="#sec-03">&#9679</a></li>
                <li class="sec-04"><a id="sec04" index="3" data="#sec-04">&#9679</a></li>
    </ul>
  </nav>
</div>
              
            
!

CSS

              
                body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
}
a{
   text-decoration: none;
}
li{
  list-style-type: none
}

section {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: sans-serif;
  font-size: 10vmin;
  color: #f5f5f5;
}

section:nth-of-type(1) {
  background: orange;
  z-index: 1;
}

section:nth-of-type(2) {
  background: blue;
}

section:nth-of-type(3) {
  background: yellow;
}
section:nth-of-type(4) {
  background: red;
}

 .dot-indicator {
        position: fixed;
        z-index: 10;
        right: 4%;
        bottom: 4%;
    }
.dot-indicator li a {
  font-size: 1.5rem;
  color: white;
}

.dot-indicator li.active a {
  color: green;
}

.dot-indicator li a:hover {
  color: red;
}

              
            
!

JS

              
                gsap.registerPlugin(Observer);

let current = 0;
let index = 0;
let animating = false;

// create array with all sections
const sections = gsap.utils.toArray("section");

// since the sections are positioned absolute, we will need to set them in the correct place first
gsap.set(sections, { yPercent: (i) => 100 * i, xPercent: (i) => 50 * i * -1 });

// create observer
// since we want to move the sections up when we mouse-wheel-scroll down
// but down when we touch- or pointer-drag down, we will need to 'invert' the logic for certain events
// easiest by setting the wheelSpeed to -1 and inverting the direction argument for the change() function
Observer.create({
  target: window,
  type: "wheel,touch,pointer",
  wheelSpeed: -1,
  onUp: () => change(1),
  onDown: () => change(-1)
});

function change(direction) {
  // check to only do things if we are not already animating
  if (!animating) {
    // check to only do things so we don't end up beyond the first or last section
    if (
      !(current === 0 && direction === -1) &&
      !(current === sections.length - 1 && direction === 1)
    ) {
      console.log("start tweening");

      animating = true;

      // set up the timeline to animate things
      const tl = gsap.timeline({
        // onComplete of the timeline update the current variable
        onComplete: function () {
          current += direction;
          animating = false;
          console.log("end tweening");
        }
      });

      tl.to(sections, { scale: 0.9 });
      tl.to(
        sections,
        { yPercent: "-=" + direction * 100, xPercent: "+=" + direction * 50 },
        "<+=0.4"
      );
      tl.to(sections, { scale: 1 }, "<+=0.4");
    } else {
      console.log("nowhere to go");
    }
  }
}
/*****************************************************************/
const dots = document.querySelectorAll('.dot-indicator  a');
Array.from(dots).forEach(function(dot) {
    dot.addEventListener('click', function() {
        index = this.getAttribute("index");
        console.log("index:" + index + "current :" + current);
        direction = index - current;
        change(direction);
    });
});

// Dot Indicator
window.addEventListener("DOMContentLoaded", () => {
  const observer = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      const id = entry.target.getAttribute("id");
      if (entry.intersectionRatio > 0) {
        document
          .querySelector(`.dot-indicator li a[data="#${id}"]`)
          .parentElement.classList.add("active");
      } else {
        document
          .querySelector(`.dot-indicator li a[data="#${id}"]`)
          .parentElement.classList.remove("active");
      }
    });
  });

  // Track all sections that have an `id` applied
  document.querySelectorAll("section[id]").forEach((section) => {
    observer.observe(section);
  });
});

              
            
!
999px

Console