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

              
                mixin Destination(name, caption, photo)
  .destination.folded
    h1= name
    hr
    p.caption= caption
    button Discover
    img(src=photo, alt=`Beautiful ${name}`)

.wrapper.loading
  +Destination("Iceland", "Fire and ice", "https://source.unsplash.com/ABtmE3jhaPQ/800x600")
  +Destination("Canada", "Genuine wilderness", "https://source.unsplash.com/DlkF4-dbCOU/800x600")
  +Destination("Norway", "Arctic gateway", "https://source.unsplash.com/6f_ANCcbj3o/800x600")
  +Destination("Greenland", "Epic landscapes", "https://source.unsplash.com/iWIDgeUbskQ/800x600")

              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Roboto:400,400i,700");

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: Roboto, sans-serif;

  @media screen and (max-width: 500px) {
    font-size: 0.8rem;
  }

  @media screen and (max-height: 500px) {
    font-size: 0.8rem;
  }
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #00080e;
}

* {
  box-sizing: border-box;
}

.wrapper {
  display: flex;
  width: 100%;
  max-width: 800px;
  height: 75%;
  max-height: 600px;
  perspective: 500px;
  transform-style: preserve-3d;
  transition: opacity 150ms ease-in-out;

  &.loading {
    opacity: 0;
  }
}

.destination {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: white;
  text-shadow: 0 0 6px #00080e;
  transition: all 150ms ease-out;

  & h1 {
    font-size: 2.5em;
    text-align: center;
  }

  & hr {
    height: 1px;
    background-color: white;
    border: none;
    width: 50px;
  }

  & p {
    font-size: 1.2em;
  }

  & button {
    border: none;
    background-color: #b71c1c;
    font-family: inherit;
    color: white;
    font-size: 1em;
    padding: 0.5em 1em;
    margin-top: 1em;
    border-radius: 2em;
    cursor: pointer;

    &:hover {
      background-color: #d32f2f;
    }
  }

  & img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    object-fit: cover;
  }

  &::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    transition: opacity 100ms ease-in;
    mix-blend-mode: multiply;
    opacity: 0;
    pointer-events: none;
  }

  &.unfolded {
    flex: 8 1;

    &.front {
      transform: translateZ(20px);
    }
    &.back {
      transform: translateZ(-20px);

      &::after {
        background: linear-gradient(
          to right,
          black 0%,
          white 25%,
          white 75%,
          black 100%
        );
        opacity: 0.5;
      }
    }
  }

  &.folded {
    flex: 1 8;

    & h1,
    & hr,
    & p,
    & button {
      display: none;
    }

    &::after {
      opacity: 0.6;
    }

    &.right {
      transform: rotateY(-30deg) scaleX(1.16);

      &::after {
        background: linear-gradient(to left, white, black);
      }
    }
    &.left {
      transform: rotateY(30deg) scaleX(1.16);

      &::after {
        background: linear-gradient(to right, white, black);
      }
    }
  }
}

              
            
!

JS

              
                import { throttle } from "https://cdn.skypack.dev/lodash@4.17.20";

class Carousel {
  static getDest(element) {
    if (!(element instanceof Element)) return;
    if (element === document.documentElement) return;
    if (element.classList.contains("destination")) return element;
    return Carousel.getDest(element.parentElement);
  }

  constructor(element) {
    this.wrapperElement = element;
    this.dests = [...element.querySelectorAll(".destination")];
    this.active = null;
    this.update();
    this.wrapperElement.classList.remove("loading");

    this.wrapperElement.addEventListener("mouseover", (event) => {
      const dest = Carousel.getDest(event.target);
      if (typeof dest === "undefined") return;
      if (dest === this.dests[this.active]) return;
      this.activate(dest);
    });

    this.wrapperElement.addEventListener(
      "mouseleave",
      throttle((event) => {
        console.log("mouseleave happening");
        if (event.target === this.wrapperElement) this.deactivate();
      }, 500)
    );
  }

  getIndex(dest) {
    if (!this.dests.includes(dest)) return;
    let i = 0;
    for (let currentDest of this.dests) {
      if (dest === currentDest) {
        return i;
      }
      i++;
    }
  }

  activate(dest) {
    this.active = this.getIndex(dest) ?? null;
    this.update();
  }

  deactivate() {
    this.active = null;
    this.update();
  }

  update() {
    this.dests.forEach((dest, index) => {
      dest.className = "destination";

      if (index === this.active) {
        dest.classList.add("unfolded", isOdd(index) ? "back" : "front");
      } else {
        dest.classList.add("folded");

        if (this.active === null || index < this.active) {
          dest.classList.add(isOdd(index) ? "right" : "left");
        } else if (index > this.active) {
          dest.classList.add(isOdd(index) ? "left" : "right");
        }
      }
    });
  }
}

function isOdd(value) {
  return value % 2 === 0;
}

const carousel = new Carousel(document.querySelector(".wrapper"));

              
            
!
999px

Console