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 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>
    <div class="bg">
        <div class="bg-main">
            <div class="bg-main-img"></div>
        </div>
        <div class="bg-circle-wrapper">
            <div class="bg-circle">
                <div class="bg-circle-img"></div>
            </div>
        </div>
    </div>

    <div class="btns">
        <button class="arrow prev" onclick="go('prev')"></button>
        <button class="arrow next" onclick="go('next')"></button>
    </div>

    <div class="text">
        <p>Use <kbd>▲</kbd> <kbd>▼</kbd> / scroll / swipe / arrows to navigate.</p>
        <p><a href="https://codepen.io/theseventh" target="_blank">codepen</a> // <a href="https://twitter.com/the_seventh_kek" target="_blank">twitter</a>
    </div>
</main>
              
            
!

CSS

              
                html, body {
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  background-color: #20303e;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  font-family: "Ubuntu", sans-serif;
  user-select: none;
}

@keyframes spin {
  from {
    transform: rotate(0);
  }
  to {
    transform: rotate(360deg);
  }
}

*, *::after, *::before {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  cursor: none;
}

main {
  width: 85vw;
  height: 80vh;
  box-shadow: 0 16px 18px rgba(22, 35, 43, 0.19);
  transform: rotate(0);

  .bg {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;

    &-main {
      width: 100%;
      height: 100%;
      position: relative;

      &-img {
        width: 100%;
        height: 100%;
        position: relative;
        background-image: var(--img);
        background-size: cover;
        background-position: center;
      }
    }

    &-circle {
      &-wrapper {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 0;
        width: 100%;
        height: 100%;
        z-index: 10;
      }

      width: 32vmin;
      height: 32vmin;
      overflow: hidden;
      clip-path: circle(16vmin at center);

      &-img {
        width: 100%;
        height: 100%;
        clip-path: circle(16vmin at center);
        position: relative;
        transform: rotate(0);

        &::after {
          content: '';
          position: fixed;
          width: 85vw;
          height: 80vh;
          display: block;
          background-image: var(--img);
          top: calc(-40vh + 16vmin);
          left: calc(-85vw / 2 + 16vmin);
          background-size: cover;
          background-position: center;
        }
      }
    }

    &::after {
      content: '';
      position: absolute;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      background: rgba(39, 108, 190, 0.33);
      mix-blend-mode: exclusion;
      z-index: 20;
    }
  }
}

.cursor {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #eae3cf;
  mix-blend-mode: hard-light;
  position: fixed;
  z-index: 999;
  pointer-events: none;
  transition: opacity .4s;
  top: -30px;
  left: -30px;

  &-f {
    position: fixed;
    border-radius: 50%;
    border: 1px dashed #eae3cf;
    width: 30px;
    height: 30px;
    pointer-events: none;
    animation: spin 2.6s linear infinite paused;
    transition: background-color .3s;
    --next: 0;
    --prev: 0;
  }

  &.clicked {
    .cursor-f {
      background-color: rgba(234, 227, 207, 0.12);
    }
  }

  &.hidden {
    opacity: 0;
  }
}

.btns {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  right: 0;
  margin: auto;
  width: fit-content;
  z-index: 999;
  mix-blend-mode: exclusion;
  transition-duration: .6s;

  &.hidden {
    opacity: 0;
    pointer-events: none;
  }

  .arrow {
    display: block;
    width: 2vmax;
    height: 1vmax;
    border: none;
    background: url("data:image/svg+xml,%3Csvg width='14' height='7' viewBox='0 0 14 7' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 6L7 1L13 6' stroke='%23EAE3CF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E%0A") no-repeat center;
    background-size: 100%;
    margin: .5vmax 0;
    padding: 1vmax 0;
    transition-duration: .3s;

    &.next {
      transform: rotate(180deg);

      &:hover {
        transform: rotate(180deg) translateY(-4px);
      }
    }

    &.prev:hover {
      transform: translateY(-4px);
    }
  }
}

.text {
  color: rgba(255, 255, 255, 0.65);
  position: absolute;
  bottom: .4em;
  font-size: .85em;
  width: 100%;
  z-index: 999;
  text-shadow: 1px 1px 0 #75757547;
  text-align: end;

  p {
    margin: .6em .9em;
  }

  a {
    color: rgba(255, 255, 255, 0.44);
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.25);

    &:hover {
      padding-bottom: 2px;
    }
  }

  kbd {
    width: 13px;
    height: 13px;
    border: 1px solid rgba(255, 255, 255, 0.59);
    display: inline-block;
    border-radius: 3px;
    font-size: .76em;
    vertical-align: middle;
    text-align: center;
  }
}
              
            
!

JS

              
                const main = document.querySelector('main');
const bg = document.querySelector('.bg-main');
const circle = document.querySelector('.bg-circle');
const btns = document.querySelector('.btns');

const cursor = document.createElement('div');
cursor.className = 'cursor';
document.body.appendChild(cursor);

const cursorF = document.createElement('div');
cursorF.className = 'cursor-f';
cursor.appendChild(cursorF);

let images = ['https://images.unsplash.com/photo-1568983527878-8baf5dabbda4?auto=format&fit=crop&w=2700', 'https://images.unsplash.com/photo-1575402770603-8915aa0d5eab?auto=format&fit=crop&w=2978', 'https://images.unsplash.com/photo-1575402758837-d55c2158c7fc?auto=format&fit=crop&w=2704'];
let current = 0;

bg.querySelector('.bg-main-img').style.setProperty('--img', `url(${images[0]})`);
circle.querySelector('.bg-circle-img').style.setProperty('--img', `url(${images[0]})`);

let bgCurrent, bgNext, circleCurrent, circleNext, playing = false;

let dirToSign = {next: 1, prev: -1};
let signToDir = {'1': 'next', '-1': 'prev'};

function go(dir = 'next') {
  if (!playing) {
    playing = true;
    btns.classList.add('hidden');
    cursorF.style.animationPlayState = 'running';
    current += dirToSign[dir];
    if (current < 0) current = images.length - 1;
    else if (current >= images.length) current = 0;

    let animOptions = {delay: .3, duration: 1.5, ease: Power3.easeInOut};

    circleCurrent = circle.querySelector('.bg-circle-img');
    circleNext = document.createElement('div');
    circleNext.style.setProperty('--img', `url(${images[current]})`);
    circleNext.className = 'bg-circle-img';

    bgCurrent = bg.querySelector('.bg-main-img');
    bgNext = document.createElement('div');
    bgNext.style.setProperty('--img', `url(${images[current]})`);
    bgNext.className = 'bg-main-img';

    let timeline = gsap.timeline({
      onComplete: function () {
        circleCurrent.remove();
        bgCurrent.remove();
        gsap.to(circleNext, {duration: 0, rotation: 0, y: 0});
        gsap.to(bg, {duration: 0, y: 0});
        cursorF.style.animationPlayState = 'paused';
        btns.classList.remove('hidden');
        playing = false;
      }, paused: false
    });

    if (dir === 'prev') {
      circle.appendChild(circleNext);
      bg.prepend(bgNext);
      gsap.to(bg, {duration: 0, y: -main.offsetHeight});

      timeline.to([circleCurrent, circleNext], {...animOptions, rotation: -180});
      timeline.to([circleCurrent, circleNext], {...animOptions, y: -circle.offsetHeight});
      timeline.to(bg, {...animOptions, y: 0}, 1.8);
      timeline.to(circleNext, {...animOptions, rotation: -360});
    }

    else {
      circle.prepend(circleNext);
      gsap.to([circleNext, circleCurrent], {duration: 0, y: -circle.offsetHeight});
      bg.appendChild(bgNext);

      timeline.to([circleCurrent, circleNext], {...animOptions, rotation: 180});
      timeline.to([circleCurrent, circleNext], {...animOptions, y: 0});
      timeline.to(bg, {...animOptions, y: -main.offsetHeight}, 1.8);
      timeline.to(circleNext, {...animOptions, rotation: 360});
    }
  }
}

let cursorX = 0;
let cursorY = 0;
let pageX = 0;
let pageY = 0;

function lerp(start, end, amount) {
  return (1-amount)*start+amount*end
}

if ('ontouchstart' in window) {
  cursor.style.display = 'none';
  cursorF.style.display = 'none';
}

document.addEventListener('mouseleave', function() {
  cursor.classList.add('hidden');
});
document.addEventListener('mouseenter', function() {
  cursor.classList.remove('hidden');
});

let clicked = false;
let startY, endY;

function mousedown(e) {
  cursor.classList.add('clicked');

  clicked = true;
  startY = e.clientY || e.touches[0].clientY || e.targetTouches[0].clientY;
}
function mouseup(e) {
  cursor.classList.remove('clicked');

  endY = e.clientY || endY;
  if (clicked && startY && Math.abs(startY - endY) >= 40) {
    go(signToDir[Math.sign(startY - endY)]);
    clicked = false;
    startY = null;
    endY = null;
  }
}
window.addEventListener('mousedown', mousedown, false);
window.addEventListener('touchstart', mousedown, false);
window.addEventListener('touchmove', function(e) {
  if (clicked) {
    endY = e.touches[0].clientY || e.targetTouches[0].clientY;
  }
}, false);
window.addEventListener('touchend', mouseup, false);
window.addEventListener('mouseup', mouseup, false);

window.addEventListener('mousemove', function(e) {
  pageX = e.clientX;
  pageY = e.clientY;
  gsap.to(cursor, {duration: .01, left: e.clientX-4, top: e.clientY-4});
});

function loop() {
  if (cursorX !== pageX || cursorY !== pageY) {
    cursorX = lerp(cursorX, pageX, .2);
    cursorY = lerp(cursorY, pageY, .2);
    gsap.to(cursorF, {duration: .01, left: cursorX - 15, top: cursorY - 15});
  }
  requestAnimationFrame(loop);
}

loop();

window.addEventListener('keydown', function(e) {
  if (['ArrowDown', 'ArrowRight'].includes(e.key)) {
    go('next');
  }

  else if (['ArrowUp', 'ArrowLeft'].includes(e.key)) {
    go('prev');
  }
});

let scrollTimeout;
function wheel(e) {
  let dir = signToDir[Math.sign(e.deltaY)];
  clearTimeout(scrollTimeout);

  setTimeout(function() {
    if (e.deltaY >= 40 || e.deltaY <= -40) go(dir);
  }, 100)
}
window.addEventListener('mousewheel', wheel, false);
window.addEventListener('wheel', wheel, false);
              
            
!
999px

Console