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

              
                <div>
  <div class="loading-container">
    <div class="loading"></div>
  </div>
  <div class="container">
    <div class="card-wrapper">
      <div class="card"></div>
    </div>
    <div class="card-wrapper">
      <div class="card"></div>
    </div>
    <div class="card-wrapper">
      <div class="card"></div>
    </div>
  </div>
  <script src="script.js"></script>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
  font-family: sans-serif;
}

body {
  background: #004b;
}

body > div {
  transform: translateY(-100px);
  transition: 0.4s 0.22s ease-in-out;
}

.d-none {
  display: none !important;
}

.container {
  padding: 20px;
}

.card-wrapper {
  perspective: 1000px;
}

.card {
  height: 200px;
  width: 100%;
  background: #fc3;
  border-radius: 20px;
  margin-bottom: 25px;
  transform-style: preserve-3d;
  transition: all 0.2s ease-out;
  box-shadow: 0px 25px 25px rgba(0, 0, 0, 0.4);
  transform: rotateX(0deg);
}

.loading-container {
  height: 100px;
  padding: 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.loading-container .loading {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 4px solid transparent;
  border-top-color: #fff;
  border-right-color: #fff;
  animation: loading 0.5s infinite forwards;
}

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

              
            
!

JS

              
                const pStart = { x: 0, y: 0 };
const pCurrent = { x: 0, y: 0 };
const cards = document.querySelectorAll(".card");
const main = document.querySelector("body > div");
let isLoading = false;

function loading() {
  isLoading = true;
  main.style.transform = `translateY(0px)`;
  setTimeout(() => {
    main.style.transform = `translateY(-100px)`;
    isLoading = false;
    for (const card of cards) {
      card.style.transform = `rotateX(0deg)`;
    }
  }, 2000);
}

function swipeStart(e) {
  if (typeof e["targetTouches"] !== "undefined") {
    let touch = e.targetTouches[0];
    pStart.x = touch.screenX;
    pStart.y = touch.screenY;
  } else {
    pStart.x = e.screenX;
    pStart.y = e.screenY;
  }
}

function swipeEnd(e) {
  if (document.body.scrollTop === 0 && !isLoading) {
    for (const card of cards) card.style.transform = `rotateX(0deg)`;
  }
}

function swipe(e) {
  if (typeof e["changedTouches"] !== "undefined") {
    let touch = e.changedTouches[0];
    pCurrent.x = touch.screenX;
    pCurrent.y = touch.screenY;
  } else {
    pCurrent.x = e.screenX;
    pCurrent.y = e.screenY;
  }
  let changeY = pStart.y < pCurrent.y ? Math.abs(pStart.y - pCurrent.y) : 0;
  const rotation = changeY < 100 ? changeY * 30 / 100 : 30;
  if (document.body.scrollTop === 0) {
    if (changeY > 100) loading();
    for (const card of cards) card.style.transform = `rotateX(${rotation}deg)`;
  }
}

document.addEventListener("touchstart", e => swipeStart(e), false);
document.addEventListener("touchmove", e => swipe(e), false);
document.addEventListener("touchend", e => swipeEnd(e), false);

              
            
!
999px

Console