Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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 class="card" data-active="false">
<img src="https://assets.codepen.io/605876/headshot--square.jpeg" alt="" />
</div>
              
            
!

CSS

              
                @import "https://unpkg.com/open-props/normalize.min.css";
@import "https://unpkg.com/open-props/open-props.min.css";

* {
  box-sizing: border-box;
}

body {
  perspective: 100vmin;
}

img {
  width: 100%;
  object-fit: cover;
  height: 100%;
  scale: 1.2;
  translate: 0 0;
  filter: grayscale(1);
}

.card:not(:hover) img {
  transition: translate 0.2s;
}

.card:hover img {
  translate:
    calc((var(--ratio-x) - 0.5) * 20%)
    calc((var(--ratio-y) - 0.5) * 20%);
}

.card {
  --ratio-x: 0;
  --ratio-y: 0;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  width: clamp(260px, 50vmin, 320px);
  border-radius: 8px;
  transform-style: preserve-3d;
  touch-action: none;
  transition: transform 0.2s;
}

.card[data-active="true"][data-parallax="true"] {
  transition: transform 0s;
}

.card:hover {
/*   transition: transform 0s; */
  transform:
    rotateX(calc((var(--ratio-y) - 0.5) * 50deg))
    rotateY(calc((var(--ratio-x) - 0.5) * -40deg));
}

.card:after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at calc(var(--ratio-x) * 100%) calc(var(--ratio-y) * 100%), hsl(0 0% 100% / 0.5), transparent 50%);
  background-repeat: no-repeat;
  background-blend-mode: soft-light;
  z-index: 2;
}

.card:before {
  content: "";
  background:
   url(https://assets.codepen.io/605876/code-icon-bg.svg) 0 0 / 18% 18%,
   linear-gradient(115deg,
     transparent 20%,
     var(--green-8) 30%,
     transparent 48% 52%,
     var(--indigo-8) 70%,
     transparent
   )
   80% 80% / 300% 300%;
  filter: brightness(2) contrast(1);
  background-blend-mode: overlay;
  mix-blend-mode: color-dodge;
  position: absolute;
  inset: 0;
  z-index: 2;
  opacity: 0.2;
  transition: opacity 0.2s;
}

.card:hover:before {
  background-position:
    calc(var(--ratio-x) * 10%) calc(var(--ratio-y) * 10%),
    calc(80% + (var(--ratio-x) * -50%)) calc(80% + (var(--ratio-y) * -50%));
  opacity: 1;
}

html {
  color-scheme: dark only;
}
@layer base {
  :root {
    --font-size-min: 16;
    --font-size-max: 20;
    --font-ratio-min: 1.2;
    --font-ratio-max: 1.33;
    --font-width-min: 375;
    --font-width-max: 1500;
  }

  html {
    color-scheme: dark only;
  }

  [data-theme='light'] {
    color-scheme: light only;
  }

  [data-theme='dark'] {
    color-scheme: dark only;
  }

  :where(.fluid) {
    --fluid-min: calc(
      var(--font-size-min) * pow(var(--font-ratio-min), var(--font-level, 0))
    );
    --fluid-max: calc(
      var(--font-size-max) * pow(var(--font-ratio-max), var(--font-level, 0))
    );
    --fluid-preferred: calc(
      (var(--fluid-max) - var(--fluid-min)) /
        (var(--font-width-max) - var(--font-width-min))
    );
    --fluid-type: clamp(
      (var(--fluid-min) / 16) * 1rem,
      ((var(--fluid-min) / 16) * 1rem) -
        (((var(--fluid-preferred) * var(--font-width-min)) / 16) * 1rem) +
        (var(--fluid-preferred) * var(--variable-unit, 100vi)),
      (var(--fluid-max) / 16) * 1rem
    );
    font-size: var(--fluid-type);
  }

  *,
  *:after,
  *:before {
    box-sizing: border-box;
  }

  body {
    background: light-dark(#fff, #000);
    display: grid;
    place-items: center;
    min-height: 100vh;
    font-family: 'SF Pro Text', 'SF Pro Icons', 'AOS Icons', 'Helvetica Neue',
      Helvetica, Arial, sans-serif, system-ui;
  }

  body::before {
    --size: 45px;
    --line: color-mix(in hsl, canvasText, transparent 70%);
    content: '';
    height: 100vh;
    width: 100vw;
    position: fixed;
    background: linear-gradient(
          90deg,
          var(--line) 1px,
          transparent 1px var(--size)
        )
        50% 50% / var(--size) var(--size),
      linear-gradient(var(--line) 1px, transparent 1px var(--size)) 50% 50% /
        var(--size) var(--size);
    mask: linear-gradient(-20deg, transparent 50%, white);
    top: 0;
    transform-style: flat;
    pointer-events: none;
    z-index: -1;
  }

  .bear-link {
    color: canvasText;
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: 48px;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    opacity: 0.8;
  }

  :where(.x-link, .bear-link):is(:hover, :focus-visible) {
    opacity: 1;
  }

  .bear-link svg {
    width: 75%;
  }

  /* Utilities */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }
}

              
            
!

JS

              
                console.clear()

const CARD = document.querySelector('.card')

const UPDATE = ({ x, y }) => {
  const BOUNDS = CARD.getBoundingClientRect()
  // Calculate the range between the center and the pointer position.
  const posX = x - BOUNDS.x
  const posY = y - BOUNDS.y
  const ratioX = posX / BOUNDS.width
  const ratioY = posY / BOUNDS.height
  // CARD.style.setProperty('--x', posX)
  // CARD.style.setProperty('--y', posY)
  CARD.style.setProperty('--ratio-x', ratioX)
  CARD.style.setProperty('--ratio-y', ratioY)
  // console.info({ posX, posY })
}


document.body.addEventListener('pointermove', UPDATE)

CARD.addEventListener('pointerenter', () => {
  CARD.dataset.active = "true"
})
CARD.addEventListener('pointerleave', () => {
  CARD.dataset.active = "false"
  CARD.dataset.parallax = "false"
})
CARD.addEventListener('transitionend', event => {
  if (event.target === CARD && event.propertyName === 'transform' && CARD.dataset.active === "true") {
    CARD.dataset.parallax = "true"
  }
})
              
            
!
999px

Console