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

              
                .crowd
  - for (let e = 0; e < 200; e++)
    .emoji(class=`${Math.random() > 0.5 ? 'emoji--man' : 'emoji--woman'}`)
.spotlight

              
            
!

CSS

              
                :root
  --x 250
  --y 250

*
  box-sizing border-box

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

.crowd
  display grid
  grid-template-rows repeat(10, 48px)
  grid-template-columns repeat(20, 54px)
  max-width 100vw
  overflow hidden

.spotlight
  position fixed
  top 0
  right 0
  bottom 0
  left 0
  opacity .95
  background -webkit-radial-gradient(calc(var(--x) * 1px) calc(var(--y) * 1px), circle cover, transparent 0px, #111 100px)

.emoji
  font-size 54px
  width 54px
  &--man
    &:after
      content '🙍‍♂️'
    &.emoji--chosen
      &:after
        content '🙆‍♂️'

  &--woman
    &:after
      content '🙍‍'
    &.emoji--chosen
      &:after
        content '🙆‍'
              
            
!

JS

              
                const spotlight = document.querySelector('.spotlight')
const crowd = document.querySelector('.crowd')
const root = document.documentElement
const spotlightUpdate = (e) => {
  const crowdPos = crowd.getBoundingClientRect()
  let {
    pageX: x,
    pageY: y
  } = e
  if (e.touches && e.touches.length) {
    x = e.touches[0].clientX
    y = e.touches[0].clientY
  }

  root.style.setProperty('--x', x)
  root.style.setProperty('--y', y)
  const chosen = document.querySelector('.emoji--chosen')
  if (chosen) chosen.classList.remove('emoji--chosen')
  // Work out which emojis are in range
  const spectatorSize = crowd.children[0].getBoundingClientRect()
  // position X is x - crowd.left
  const left = x - crowdPos.left
  const top = y - crowdPos.top
  if (!(left < 0 || left > crowdPos.width) && !(top < 0 || top > crowdPos.height)) {
    const emojiX = Math.floor(left / spectatorSize.width)
    const emojiY = Math.floor(top / spectatorSize.height)
    const chosen = (emojiY * 20) + emojiX
    crowd.children[chosen].classList.add('emoji--chosen')
  }
}
root.style.setProperty('--x', window.innerWidth / 2)
root.style.setProperty('--y', window.innerHeight / 2)
document.addEventListener('touchmove', spotlightUpdate)
document.addEventListener('mousemove', spotlightUpdate)
              
            
!
999px

Console