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

              
                -
  const PICS = [
    'https://images.unsplash.com/photo-1542662565-7e4b66bae529?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=282&q=80',
    'https://images.unsplash.com/photo-1525153537143-f88592837fb1?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=332&q=80',
    'https://images.unsplash.com/photo-1477346611705-65d1883cee1e?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80',
    'https://images.unsplash.com/photo-1507400492013-162706c8c05e?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=309&q=80',
    'https://images.unsplash.com/photo-1436891620584-47fd0e565afb?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=334&q=80',
    'https://images.unsplash.com/photo-1519681393784-d120267933ba?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&auto=format&fit=crop&w=750&q=80'
  ]
  const TITLES = ['Mountain', 'Stars', 'Skies', 'Water', 'Trips']
  const TYPE = ['Guide', 'Planner', 'Discuss']
mixin cardContent(idx, reflection)
  .card__content.bg-gray-800.overflow-hidden.relative.h-full.w-full.rounded-md.font-sans
    img.card__image.transform.absolute.h-full.w-full.inset-0.transform.scale-110(src=PICS[idx % PICS.length])
    .card__details.absolute.inset-0.pt-52.flex.items-center.justify-center.flex-col
      .card__type.text-gray-300.top-0.uppercase.text-xs.p-0.w-full.text-center= TYPE[Math.floor(Math.random() * TYPE.length)]
      h2.card__title.p-2.text-white.font-black.text-xl.text-center.w-full.pb-12= TITLES[idx % TITLES.length]
  .card__overlay.z-50.absolute.h-full.w-full.inset-0(class=`${reflection ? 'card__overlay--reflection' : ''}`)

mixin card(idx)
  li.gallery__card.card.w-56.h-72.absolute
    .card__card.h-full.w-full
      +cardContent(idx, false)
    .card__reflection.absolute.h-full.w-full.top-8.left-0.rounded-md.overflow-hidden(aria-hidden="true")
      +cardContent(idx, true)
.gallery.opacity-0.fixed.w-56.h-72.transform(class="top-1/2 left-1/2 -translate-y-2/4 -translate-x-2/4")
  ul.gallery__content
    - let c = 0
    while c < 50
      +card(c)
      - c++
  .gallery__actions
    button.gallery__prev.outline-none.absolute.z-10.rounded-full.transition.right-full.transform-gpu.opacity-50(class="-translate-x-36 top-1/2 -translate-y-1/2 hover:opacity-100")
      span.sr-only Prev
      svg.h-12.w-12.fill-current.text-white(viewBox="0 0 256 512" title="Previous")
        path(d="M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z")
    button.gallery__next.outline-none.absolute.z-10.rounded-full.left-full.transform-gpu.transition.opacity-50(class="translate-x-36 top-1/2 -translate-y-1/2 hover:opacity-100")
      span.sr-only Next
      svg.h-12.w-12.fill-current.text-white(viewBox="0 0 256 512" title="Next")
        path(d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z")

              
            
!

CSS

              
                *
  box-sizing border-box

:root
  --bg hsl(220, 34%, 5%)
  --overlay 'hsla(0, 10%, 10%, %s)' % var(--alpha-overlay, 0)

body
  background var(--bg)
  min-height 100vh

img
  object-fit cover

.card
  &[data-current="true"] > .card__card .card__overlay
    display none

  &__overlay
    &--reflection
      background linear-gradient(hsl(220, 34%, 5%) 50%, transparent)

  &__reflection
    filter blur(4px)
    transform translate3d(0, 0, 0) rotate(180deg) translate(0, -100%) rotateY(180deg)

    .card__details
      background transparent

    .card__content
      clip-path inset(50% 0 0 0)
              
            
!

JS

              
                import gsap from 'https://cdn.skypack.dev/gsap'
import ScrollTrigger from 'https://cdn.skypack.dev/gsap/ScrollTrigger'

const {
  to,
  set,
  registerPlugin,
  utils: { mapRange, pipe },
} = gsap
registerPlugin(ScrollTrigger)

const CARDS = [...document.querySelectorAll('.gallery__card')]
const NEXT = document.querySelector('.gallery__next')
const PREV = document.querySelector('.gallery__prev')

const getIndex = pipe(mapRange(0, 1, 0, CARDS.length), Math.floor)

// Set the body
set(document.body, {
  width: CARDS.length * CARDS[0].offsetWidth,
})

let INDEX = 20

set(CARDS, {
  opacity: 1,
  scale: 0.01,
})

const AUDIO = {
  WHOOSH: new Audio('https://assets.codepen.io/605876/whoosh-two.mp3'),
}

AUDIO.WHOOSH.volume = 0.5

const playWhoosh = () => {
  AUDIO.WHOOSH.currentTime = 0
  AUDIO.WHOOSH.play()
}

const STATE_MAP = {
  duration: 0.1,
  alpha: [1, 1, 0.75, 0.5, 0, 0.5, 0.75, 1, 1],
  xPercent: [-75, -100, -75, -50, 0, 50, 75, 100, 75],
  scale: [0, 0, 0.25, 0.5, 1, 0.5, 0.25, 0, 0],
  rotateY: [180, 140, 100, 90, 0, -90, -100, -140, -180],
  zIndex: [0, 0, 1, 2, 3, 2, 1, 0, 0],
}

const RENDER = (scroller, initial) => {
  const NEW_INDEX = getIndex(scroller.progress)
  INDEX = NEW_INDEX
  const L1 = INDEX - 1 < 0 ? null : INDEX - 1
  const L2 = INDEX - 2 < 0 ? null : INDEX - 2
  const L3 = INDEX - 3 < 0 ? null : INDEX - 3
  const U1 = INDEX + 1 > CARDS.length - 1 ? null : INDEX + 1
  const U2 = INDEX + 2 > CARDS.length - 1 ? null : INDEX + 2
  const U3 = INDEX + 3 > CARDS.length - 1 ? null : INDEX + 3

  const MAP = [L3, L2, L1, INDEX, U1, U2, U3]

  const addProperty = (index, prop) => {
    // Plus One is important to avoid the padding
    if (MAP.indexOf(index) !== -1)
      return STATE_MAP[prop][MAP.indexOf(index) + 1]
    else
      return index < INDEX
        ? STATE_MAP[prop][0]
        : STATE_MAP[prop][STATE_MAP[prop].length - 1]
  }

  to(CARDS, {
    onComplete: () => {
      if (initial) to('.gallery', { onStart: () => playWhoosh(), opacity: 1 })
      else playWhoosh()
      set(CARDS, {
        attr: { 'data-current': index => (index === INDEX ? 'true' : 'false') },
      })
      set('.gallery__prev', { display: INDEX === 0 ? 'none' : 'block' })
      set('.gallery__next', {
        display: INDEX === CARDS.length - 1 ? 'none' : 'block',
      })
    },
    duration: 0.1,
    scale: index => addProperty(index, 'scale'),
    xPercent: index => addProperty(index, 'xPercent'),
    zIndex: index => addProperty(index, 'zIndex'),
    '--overlay-alpha': index => addProperty(index, 'alpha'),
  })
}
const SCROLLER = ScrollTrigger.create({
  horizontal: true,
  scroller: document.body,
  snap: {
    snapTo: 1 / (CARDS.length - 1),
    duration: 0.1,
  },
  onUpdate: self => {
    const NEW_INDEX = getIndex(self.progress)
    if (CARDS[NEW_INDEX] && NEW_INDEX !== INDEX) RENDER(self)
  },
})
RENDER(SCROLLER, true)
set(document.body, {
  scrollLeft: document.body.scrollWidth * 0.5,
})

// Hook up Next/Prev buttons.
NEXT.addEventListener('click', () => {
  const DESTINATION = (INDEX + 1) * ((SCROLLER.end - 0.1) / (CARDS.length - 1))
  SCROLLER.scroll(DESTINATION)
})
PREV.addEventListener('click', () => {
  SCROLLER.scroll((INDEX - 1) * ((SCROLLER.end - 0.1) / (CARDS.length - 1)))
})

              
            
!
999px

Console