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

              
                <script src="https://hammerjs.github.io/dist/hammer.js"></script>

<div class="main-view">
  
  <div class="content">
    
    <section>
      <div class="text">
        <h1>Section 1</h1>
        <p>Lorem ipsum dolor sit amet.</p>
      </div>
    </section>
    <section>
      <div class="text">
        <h1>Section 2</h1>
        <p>Lorem ipsum dolor sit amet.</p>
      </div>
    </section>
        <section>
      <div class="text">
        <h1>Section 3</h1>
        <p>Lorem ipsum dolor sit amet.</p>
      </div>
    </section>
    <div>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Deserunt animi eaque at nesciunt. Ipsa eius vel, nobis vero repellendus excepturi reprehenderit ex quis, magni eum mollitia! Fuga, sed? Dignissimos voluptatibus deserunt, ea ipsa, officia, temporibus placeat voluptatum beatae quo aliquam ducimus. Asperiores ea id exercitationem consequuntur quis unde, illum eius alias molestiae nihil totam illo beatae sapiente accusantium numquam. Libero, dignissimos dolores eaque reiciendis perspiciatis rem, suscipit facilis repellat sapiente et aperiam. Nobis iusto repellendus reprehenderit, repudiandae ipsam reiciendis aut asperiores dolorem nam rem error explicabo corporis sed possimus ea deserunt, illum dolore maiores tenetur, fugit eligendi veritatis. Eaque, quaerat!</div>
    
  </div>
  <nav>
    <button class="prev btn">Prev</button>
    <button class="next btn">Next</button>
  </nav>
  
</div>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
}
.main-view {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}
section {
  position: relative;
  width: 100vw;
  height: 100vh;
}

.text {
  position: absolute;
  top: 30%;
  left: 10%;
  font-size: 20px;
  opacity: 0;
  transform: translateY(30px);
  transition: all 300ms 500ms ease-in;
}
.text.show {
  opacity: 1;
  transform: translateY(0px);
}

section:nth-child(1) {
  background: #4587b7;
}
section:nth-child(2) {
  background: #ee5318;
}
section:nth-child(3) {
  background: #34e377;
}

nav {
  position: fixed;
  top: 20px;
  left: 20px;
}
button {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  font-size: 14px;
}
              
            
!

JS

              
                const sections = document.querySelectorAll('section');
const prevBtn = document.querySelector('.prev');
const nextBtn = document.querySelector('.next');

let counter = 0;
const animationDuration = 100;
let lastTime = 0;

const toggleText = (index, state) => {
  if (state === 'show') {
    sections.forEach((section, index) => {
      if (index === counter) {
        section.querySelector('.text').classList.add('show');
      } else {
        section.querySelector('.text').classList.remove('show');
      }
    })
  }
}

toggleText(0, 'show');


  nextBtn.addEventListener('click', (e) => {
  if (counter == sections.length - 1) return;
  counter++;
  sections.forEach((section, index) => {
    if (index === counter) {
      toggleText(index, 'show');
      section.scrollIntoView({behavior: 'smooth'});
    };
  });
});


prevBtn.addEventListener('click', () => {
  if (counter == 0) return;
  counter--;
  sections.forEach((section, index) => {
    if (index === counter) {
      toggleText(index, 'show');
      section.scrollIntoView({behavior: 'smooth'});
    };
  });
});

if (counter === sections.length - 1) {
  const swipeAre = document.querySelector('.main-view');
  swipeAre.style.overflow = 'initial';
}


window.addEventListener('wheel', (e) => {
  const delta = e.wheelDelta;
  const currentTime = new Date().getTime();
  
  if (currentTime - lastTime < animationDuration) {
    e.preventDefault();
    return;
  }
  
  
  if(delta < 0) {
    const nextBtnClick = new Event('click');
    nextBtn.dispatchEvent(nextBtnClick);
  } else {
    const prevBtnClick = new Event('click');
    prevBtn.dispatchEvent(prevBtnClick);
  }
  
    lastTime = currentTime;
  
})

const swipeArea = document.querySelector('.main-view');

const mc = new Hammer(swipeArea);

mc.get('swipe').set({ direction: Hammer.DIRECTION_ALL });

mc.on('swipeup', function() {
  nextBtn.click();
});

mc.on('swipedown', function() {
  prevBtn.click();
});

              
            
!
999px

Console