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

              
                .container
  - let b = 0
  while (b < 5)
    .bunny(style=`--index: ${b};`)
    - b++

input(type='range', min="0", max="6", value="0")

h1 No delay
h1 Delay
h1 Negative Delay
h1 Staggered
h1 Staggered w/ Negative Delay
h1 Reverse Stagger
h1 Reverse Stagger w/ Negative Delay
p Animate simulataneously with no delay
p Animate simulataneously with a delay
p Animate simulataneously with a negative delay
p Use a variable to create a stagger
p Use an offset to make the delays negative so that the elements retain stagger but don't stagger in
p Use the total amount of bunnies to reverse the stagger
p Use a negative coefficient to create a stagger in the opposite direction
pre
  code .bunny {
  code   animation-delay: 0s;
  code }
pre
  code .bunny {
  code   animation-delay: 2s;
  code }
pre
  code .bunny {
  code   animation-delay: -0.5s;
  code }
pre
  code .bunny {
  code   animation-delay: calc(var(--index) * 0.15s);
  code }
pre
  code .bunny {
  code   animation-delay: calc((var(--index) - 5) * 0.15s);
  code }
pre
  code .bunny {
  code   animation-delay: calc((5 - var(--index)) * 0.15s);
  code }
pre
  code .bunny {
  code   animation-delay: calc(var(--index) * -0.15s);
  code }
              
            
!

CSS

              
                *
  box-sizing border-box

:root
  --delay 0
  --duration 1
  --stagger-step 0
  --coefficient 1
  --offset 0

body
  background linear-gradient(-45deg, hsl(100, 50%, 40%), hsl(100, 40%, 70%))
  min-height 100vh
  display flex
  color hsl(0, 0%, 100%)
  align-items center
  font-family sans-serif
  font-size 1.2rem
  justify-content center
  flex-direction column
  text-align center

pre
code
  background hsl(0, 0%, 10%)
  font-weight bold
  font-size 1.25rem
  font-family monospace
pre
  padding 1rem
  border-radius 6px

.bunny
  height 50px
  width 50px
  background-image url("https://assets.codepen.io/605876/bunny-ready.png")
  background-size contain
  background-position center
  background-repeat no-repeat
  transform-origin 50% 100%
  animation jump calc(var(--duration) * 1s) infinite both
  animation-delay calc((((var(--delay, 0) + (var(--index) * var(--stagger-step))) + var(--offset)) * var(--coefficient)) * 1s)

@keyframes jump
  10%, 90%
    transform translate(0, 0) scaleX(1.1) scaleY(0.8)
  50%
    background-image url("https://assets.codepen.io/605876/bunny-jump.png")
    transform translate(0, -60px) scaleX(0.9) scaleY(1.2)

.reversed .bunny
  animation-delay calc((((var(--delay, 0) + ((5 - var(--index)) * var(--stagger-step))) + var(--offset)) * var(--coefficient)) * 1s)

.container
  display grid
  grid-template-columns repeat(5, 1fr)
  grid-gap 1vmin
  margin 4rem 0

h1
p
pre
  display none
  text-align left

h1
  margin-bottom 0.25rem

p
  max-width 550px

code
  line-height 1.75
  display block

[hidden] *
  animation none

              
            
!

JS

              
                // Get started!
const RANGE = document.querySelector('input')
const CONTAINER = document.querySelector('.container')
const TITLES = [...document.querySelectorAll('h1')]
const BLURBS = [...document.querySelectorAll('p')]
const CODES = [...document.querySelectorAll('pre')]

// Each config reps delay, duration, stagger, coefficient, offset
const STEP_CONFIGS = [
  [0, 0.9, 0, 1, 0],
  [2, 0.9, 0, 1, 0],
  [-0.5, 0.9, 0, 1, 0],
  [0, 0.9, 0.15, 1, 0],
  [0, 0.9, 0.15, 1, -5],
  [0, 0.9, 0.15, 1, 0],
  [0, 0.9, 0.15, -1, 0],
]

const update = () => {
  // Show/Hide elements
  for (let e = 0; e < TITLES.length; e++) {
    TITLES[e].style.display = BLURBS[e].style.display = CODES[e].style.display =
      e === parseInt(RANGE.value, 10) ? 'block' : 'none'
  }
  // Running the step function
  const CONFIG = STEP_CONFIGS[parseInt(RANGE.value, 10)]
  document.documentElement.style.setProperty('--delay', CONFIG[0])
  document.documentElement.style.setProperty('--duration', CONFIG[1])
  document.documentElement.style.setProperty('--stagger-step', CONFIG[2])
  document.documentElement.style.setProperty('--coefficient', CONFIG[3])
  document.documentElement.style.setProperty('--offset', CONFIG[4])
  if (parseInt(RANGE.value, 10) === 5) {
    CONTAINER.classList.add('reversed')
  } else {
    CONTAINER.classList.remove('reversed')
  }
  // Retrigger the animation
  CONTAINER.hidden = true
  requestAnimationFrame(() => (CONTAINER.hidden = false))
}

RANGE.addEventListener('change', update)
// Run the first time to show step 0 👍
update()

              
            
!
999px

Console