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

              
                <section class="grid">
  <div class="cube one">
    <div class="cube front face"></div>
    <div class="cube back face"></div>
    <div class="cube right face"></div>
    <div class="cube left face"></div>
    <div class="cube top face"></div>
    <div class="cube bottom face"></div>
    <div class="cube shadow"></div>
  </div>
  <div class="cube two">
  <div class="cube front face"></div>
  <div class="cube back face"></div>
  <div class="cube right face"></div>
  <div class="cube left face"></div>
  <div class="cube top face"></div>
  <div class="cube bottom face"></div>
</div>
  <div class="cube three">
  <div class="cube front face"></div>
  <div class="cube back face"></div>
  <div class="cube right face"></div>
  <div class="cube left face"></div>
  <div class="cube top face"></div>
  <div class="cube bottom face"></div>
  </div>
  <div class="cube four">
    <div class="cube front face"></div>
    <div class="cube back face"></div>
    <div class="cube right face"></div>
    <div class="cube left face"></div>
    <div class="cube top face"></div>
    <div class="cube bottom face"></div>
  </div>
  <div class="cube five">
    <div class="cube front face"></div>
    <div class="cube back face"></div>
    <div class="cube right face"></div>
    <div class="cube left face"></div>
    <div class="cube top face"></div>
    <div class="cube bottom face"></div>
  </div>
  <div class="cube six">
    <div class="cube front face"></div>
    <div class="cube back face"></div>
    <div class="cube right face"></div>
    <div class="cube left face"></div>
    <div class="cube top face"></div>
    <div class="cube bottom face"></div>
  </div>
</section>
              
            
!

CSS

              
                *,
*::before,
*::after {
  box-sizing: border-box;
  transform-style: preserve-3d;
}

body {
  margin: 0;
  padding: 0;
  background: #F7F1EA;
  overflow-x: hidden;
}

/* Cube mixin credit: @rolivaalonso */
@mixin cuboid($x, $y, $z) {
  &.front {
    @include cube-face($x, $y, $z);
  }
  &.back {
    @include cube-back($x, $y, $z);
  }
  &.right {
    @include cube-right($x, $y, $z);
  }
  &.left {
    @include cube-left($x, $y, $z);
  }
  &.bottom {
    @include cube-bottom($x, $y, $z);
  }
  &.top {
    @include cube-top($x, $y, $z);
  }
}

@mixin cube-face($x, $y, $z) {
  width: $x;
  height: $y;
  -webkit-transform-origin: bottom left;
      -ms-transform-origin: bottom left;
          transform-origin: bottom left;
  -webkit-transform: rotateX(-90deg) translateZ(-($y - ($z * 2)));
          transform: rotateX(-90deg) translateZ(-($y - ($z * 2)));
}

@mixin cube-back($x, $y, $z) {
  width: $x;
  height: $y;
  -webkit-transform-origin: top left;
      -ms-transform-origin: top left;
          transform-origin: top left;
  -webkit-transform: rotateX(-90deg) rotateY(180deg) 
    translateX(-$x) translateY(-$y);
          transform: rotateX(-90deg) rotateY(180deg) 
    translateX(-$x) translateY(-$y);
}

@mixin cube-right($x, $y, $z) {
  width: $z * 2;
  height: $y;
  -webkit-transform-origin: top left;
      -ms-transform-origin: top left;
          transform-origin: top left;
  -webkit-transform: rotateY(90deg) rotateZ(-90deg) translateZ($x) translateX(-$z * 2) translateY(-$y);
          transform: rotateY(90deg) rotateZ(-90deg) translateZ($x) translateX(-$z * 2) translateY(-$y);
}

@mixin cube-left($x, $y, $z) {
  width: $z * 2;
  height: $y;
  -webkit-transform-origin: top left;
      -ms-transform-origin: top left;
          transform-origin: top left;
  -webkit-transform: rotateY(-90deg) rotateZ(90deg) translateY(-$y);
          transform: rotateY(-90deg) rotateZ(90deg) translateY(-$y);
}

@mixin cube-top($x, $y, $z) {
  width: $x;
  height: $z * 2;
  -webkit-transform-origin: top left;
      -ms-transform-origin: top left;
          transform-origin: top left;
  -webkit-transform: translateZ($y);
          transform: translateZ($y);
}

@mixin cube-bottom($x, $y, $z) {
  width: $x;
  height: $z * 2;
  -webkit-transform-origin: top left;
      -ms-transform-origin: top left;
          transform-origin: top left;
  -webkit-transform: rotateY(180deg) translateX(-$x);
          transform: rotateY(180deg) translateX(-$x);
}

$cube-h: 3vw;
$cube-w: 25vw;
$cube-z: 8vw;

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(3rem, 1fr));
  gap: 21vw;
  max-width: 140ch;
  margin: 4rem auto 4rem;
  margin-bottom: 10rem;
  padding: 1.5rem 3rem;
  padding-right: 13rem;
  height: 100%;
  // height: 60vh;
  width: 100%;
}

.face {
  position: absolute;
}

.cube {
  @include cuboid($cube-w, $cube-h, $cube-z);
  width: $cube-w;
  height: $cube-h;
  transform: perspective(9999px) rotateX(53deg) rotateZ(-50deg);
  transform: perspective(9999px) rotateX(53deg) rotateZ(-60deg);
  top: -50%;
  left: -50%;
  margin-bottom: 2.25rem;
  
  &.front, &.back,
  &.right, &.left,
  &.top, &.bottom {
    background-color: #f06;
    background-color: #13D1C6;
    background-color: #fff;
    background-size: 100% 100%;
    background-repeat: no-repeat;
 }
  
  &.left {
    --b: .5;
    border-bottom: 3px solid #333;
    border-bottom: calc(var(--b) * 1vmin) solid #333;
    border-left: 3px solid #333;
    border-left: calc(var(--b) * 1vmin) solid #333;
    border-right: none;
    background: repeating-linear-gradient(to bottom, #eee 30%, #AAA 32%);
    background: repeating-linear-gradient(to bottom, #eee 20%, #ccc 32%);
    background: repeating-linear-gradient(to bottom, #eee 20%, #bbb 30%);
  }
  
  &.front, &.back {
    --b: .6;
    border-bottom: 3px solid #333;
    border-bottom: calc(var(--b) * 1vmin) solid #333;
    background: repeating-linear-gradient(to bottom, #fff 30%, #ddd 32%);
    background: repeating-linear-gradient(to bottom, #eee 20%, #bbb 40%);
    
  }
  
  &.one .top,
  &.two .top,
  &.three .top,
  &.four .top,
  &.five .top,
  &.six .top {
    transform: rotate(90deg) translateZ(3vw);
    background-size: 100% 100%;
    top: -50.5%;
    left: 51%;
    width: $cube-w / 1.54;
    height: $cube-h * 8.45;
    border-radius: 1px;
  }

  &.one .top {
    background-image: url("https://covers.openlibrary.org/b/id/11464254-L.jpg");
  }
  &.two .top {
    background-image: url("https://ia800603.us.archive.org/view_archive.php?archive=/24/items/olcovers656/olcovers656-L.zip&file=6564962-L.jpg");
  }
  &.three .top {
    background-image: url("https://ia800607.us.archive.org/view_archive.php?archive=/22/items/olcovers24/olcovers24-S.zip&file=240727-S.jpg");
    background-image: url("https://covers.openlibrary.org/b/id/11107659-L.jpg");
    
  }
  &.four .top {
    background-image: url("https://covers.openlibrary.org/b/id/365971-L.jpg")
  }
  &.five .top {
    background-image: url("https://covers.openlibrary.org/b/id/11574888-L.jpg");
  }
  &.six .top {
    background-image: url("https://covers.openlibrary.org/b/id/8441388-L.jpg");
  }
  &:hover {
    cursor: pointer;
  }
}

@media screen and (min-width: 1050px) {
  .cube {
    margin-bottom: 4rem;
  }
}

@media screen and (min-width: 1000px) {
  .grid {
    margin-bottom: 15rem;
  }
}

@media screen and (max-width: 750px) {
  .grid {
    padding-right: 10rem;
    max-width: 80ch;
  }
}

@media screen and (max-width: 450px) {
  .grid {
    padding-right: 5rem;
    max-width: 80ch;
  }
}
              
            
!

JS

              
                // Accessing book covers from https://openlibrary.org/dev/docs/api/covers
class OpenLib {
  constructor() {
    this.rootUrl = "https://covers.openlibrary.org";
  }
  
  // Get a single book cover image url
  async getCover(key, value, size) {
    const apiUrl = `${this.rootUrl}/b/${key}/${value}-${size}.jpg`;
    const response = await fetch(apiUrl);
    return response["status"] == 200 ? response["url"] : { "message": "Request failed", "response": response };
  }
  
  // Get a list of book cover image urls
  async getCovers(coversObjList) {
    let covers = [];
    coversObjList.forEach(cover => {
      const { key, id, size } = cover;
      const response = this.getCover(key, id, size);
      covers.push(response);
    });
    // Resolve array of promises
    return Promise.all(covers).then(c => {
      return c;
    });
  }
}

const bookList = [
  {
    title: "The Hitch Hiker's Guide to the Galaxy",
    id: 11464254,
    key: "id",
    size: "L",
    fallback: "https://covers.openlibrary.org/b/id/11464254-L.jpg"
  },
   {
    title: "Star Wars: Splinter of the Mind's Eye",
    id: 6564962,
    key: "id",
    size: "L",
    fallback: "https://ia600603.us.archive.org/view_archive.php?archive=/24/items/olcovers656/olcovers656-L.zip&file=6564962-L.jpg"
  },
  {
    title: "Star Wars: Heir to the Empire",
    id: 11107659,
    key: "id",
    size: "L",
    fallback: "https://covers.openlibrary.org/b/id/11107659-L.jpg"
  },
  {
    title: "Star Trek",
    id: 365971,
    key: "id",
    size: "L",
    fallback: "https://covers.openlibrary.org/b/id/365971-L.jpg"
  },
  {
    title: "The Hobbit",
    id: 11574888,
    key: "id",
    size: "L",
    fallback: "https://covers.openlibrary.org/b/id/11574888-L.jpg"
  },
  {
    title: "The Lion, the Witch and the Wardrobe",
    id: 8441388,
    key: "id",
    size: "L",
    fallback: "https://covers.openlibrary.org/b/id/8441388-L.jpg"
  }
];

const cubeOne = document.querySelector(".cube.one");
const cubeTwo = document.querySelector(".cube.two");
const cubeThree = document.querySelector(".cube.three");
const cubeFour = document.querySelector(".cube.four");
const cubeFive = document.querySelector(".cube.five");
const cubeSix = document.querySelector(".cube.six");
let bookNodes = [cubeOne, cubeTwo, cubeThree, cubeFour, cubeFive, cubeSix];

// Get multiple book cover images
const openLib = new OpenLib();
openLib.getCovers(bookList).then(res => {
  bookList.forEach((book, index) => {
      book["imgUrl"] = res[index];
  });
  
  bookNodes.forEach((book, index) => {
    let bookCover = book.querySelector(".top");
    bookCover.style.backgroundImage = bookList[index].imgUrl ? `url('${bookList[index].imgUrl}')` : bookList[index].fallback;
  });
});

// List of Tween objects
let tweens = bookNodes.map(node => {
  return gsap.to(`.cube.${node.className.slice(5)}`, {
    rotateY: -10,
    rotateX: -5,
    rotateZ: -90,
    translateZ: 50,
    y: -30,
    duration: .7,
    yoyo: true,
    paused: true,
    zIndex: 99
  });
});

// Animation with GSAP
let isClicked = false;
bookNodes.forEach((book, index) => {
  book.addEventListener("click", () => {
    tweens[index].play();
    if (isClicked) tweens[index].reverse();
    isClicked = !isClicked;
  });
});

              
            
!
999px

Console