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

              
                - let columns = 15
- let rows = 20
- let cells = columns * rows
button.replay
  svg.replay__icon(viewBox="0 0 24 24")
    path(d="M17.65,6.35C16.2,4.9 14.21,4 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20C15.73,20 18.84,17.45 19.73,14H17.65C16.83,16.33 14.61,18 12,18A6,6 0 0,1 6,12A6,6 0 0,1 12,6C13.66,6 15.14,6.69 16.22,7.78L13,11H20V4L17.65,6.35Z")
.bear-grid(style=`--cells: ${cells}; --columns: ${columns}; --rows: ${rows}`)
  - for(let b = 1; b < cells + 1; b++)
    .bear-grid__cell(style=`--x: ${(b - 1) % columns}; --y: ${b % columns === 0 ? Math.floor(b / columns) - 1 : Math.floor(b / columns)}; --destinationY: ${Math.floor(Math.random() * 500)}; --destinationX: ${Math.floor(Math.random() * 500)}; --rotation: ${Math.floor(Math.random() * 360)}`)

              
            
!

CSS

              
                *
  box-sizing border-box
  animation  fadeIn .5s

body
  background-color #111
  display flex
  align-items center
  justify-content center
  min-height 100vh

.bear-grid
  --height 320
  --width 240
  display grid
  grid-template-rows repeat(var(--rows), 1fr)
  grid-template-columns repeat(var(--columns), 1fr)
  height calc(var(--height) * 1px)
  transition height .25s, width .25s
  width calc(var(--width) * 1px)

  @media(min-width 768px)
    --height 400
    --width 300

  &--fading .bear-grid__cell
    animation-play-state running
    animation-name driftAway

  &__cell
    --cellWidth calc((calc(var(--width) * -1px)) / var(--columns))
    --cellHeight calc((calc(var(--height) * -1px)) / var(--rows))
    background url(https://jh3y-bear-doesnt-feel-good.netlify.com/dontfeelgoodbear.svg)
    background-size calc(var(--width) * 1px) calc(var(--height) * 1px)
    background-position calc(var(--x) * var(--cellWidth)) calc(var(--y) * var(--cellHeight))
    animation-delay calc(var(--x) * .2s + 1s)
    animation-fill-mode backwards
    animation-duration 4s
    animation-play-state paused
    opacity 0
    transform translate(calc(var(--destinationX) * -1px), calc(var(--destinationY) * -1px)) rotate(calc(var(--rotation) * 1deg)) scale(0)

.replay
  animation fadeIn .25s
  background 0
  border 0
  cursor pointer
  display none
  height 44px
  left 50%
  margin-left -22px
  margin-top -22px
  padding 0
  position fixed
  top 50%
  width 44px
  z-index 2

  &:active
    transform translateY(5%)

  &--show
    display block

  &__icon
    height 44px
    width 44px

    path
      fill #fff

@keyframes fadeIn
  from
    opacity 0

@keyframes driftAway
  from
    transform translate(0, 0) rotate(0deg) scale(1)
    opacity 1
              
            
!

JS

              
                const bearGrid = document.querySelector('.bear-grid')
const bearCells = bearGrid.querySelectorAll('.bear-grid__cell')
const lastCell = bearCells[bearCells.length - 1]
const replay = document.querySelector('.replay')


const imageHasLoaded = (src) => new Promise((resolve, reject) => {
  const img = new Image()
  img.onload = resolve
  img.onerror = reject
  img.src = src
})

const showReset = () => {
  bearGrid.classList.toggle('bear-grid--fading')
  replay.classList.toggle('replay--show')
}

const fade = () => {
  replay.classList.toggle('replay--show')
  bearGrid.classList.toggle('bear-grid--fading')
}


lastCell.addEventListener('animationend', showReset)
replay.addEventListener('click', fade)

imageHasLoaded('https://jh3y-bear-doesnt-feel-good.netlify.com/dontfeelgoodbear.svg')
  .then(() => {
    bearGrid.classList.toggle('bear-grid--fading')
  })
              
            
!
999px

Console