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 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

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

              
                <svg class="bulbs" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 679 483">
  <g class="bulb">
    <path class="bulb__chord" stroke="#C4C4C4" stroke-width="3" d="M339 411V11"/>
    <g class="bulb__bulb">
      <path stroke="none" stroke-width="3" d="M339 411V11"/>
      <circle class="bulb__glass" cx="339" cy="453" r="29" stroke="#000" stroke-width="2"/>
      <circle class="bulb__flash" cx="339" cy="453" r="30" fill="#FAFF13"/>
      <path class="bulb__glare" d="M363.977 456.827C364.667 452.176 364.106 447.425 362.352 443.062C360.599 438.699 357.716 434.881 354 432" stroke="white" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
      <path class="bulb__filament" stroke="#000" stroke-width="2" d="M339 437v13.5M343 437v13.5M347 420v24M335 437v13.5M331 420v24"/>
      <g clip-path="url(#clip0)">
        <rect class="bulb__holder" width="40" height="34" x="319" y="394" fill="#C4C4C4" rx="4"/>
        <rect class="bulb__holder-shine" width="20" height="34" x="346" y="394" fill="#F7F7F7"/>
      </g>
      <rect class="bulb__holder-outline" width="38" height="32" x="320" y="395" stroke="#000" stroke-width="2" rx="3"/>
    </g>
  </g>
  <g class="bulb">
    <g class="bulb__bulb">
      <path class="bulb__fake-chord" stroke="red" stroke-width="3" d="M339 411V11"/>
      <circle class="bulb__glass" cx="339" cy="453" r="29" stroke="#000" stroke-width="2"/>
      <circle class="bulb__flash" cx="339" cy="453" r="30" fill="#FAFF13"/>
      <path class="bulb__glare" d="M363.977 456.827C364.667 452.176 364.106 447.425 362.352 443.062C360.599 438.699 357.716 434.881 354 432" stroke="white" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
      <path class="bulb__filament" stroke="#000" stroke-width="2" d="M339 437v13.5M343 437v13.5M347 420v24M335 437v13.5M331 420v24"/>
      <g clip-path="url(#clip0)">
        <rect class="bulb__holder" width="40" height="34" x="319" y="394" fill="#C4C4C4" rx="4"/>
        <rect class="bulb__holder-shine" width="20" height="34" x="346" y="394" fill="#F7F7F7"/>
      </g>
      <rect class="bulb__holder-outline" width="38" height="32" x="320" y="395" stroke="#000" stroke-width="2" rx="3"/>
    </g>
  </g>
  <g class="bulb">
    <g class="bulb__bulb">
      <path class="bulb__fake-chord" stroke="red" stroke-width="3" d="M339 411V11"/>
      <circle class="bulb__glass" cx="339" cy="453" r="29" stroke="#000" stroke-width="2"/>
      <circle class="bulb__flash" cx="339" cy="453" r="30" fill="#FAFF13"/>
      <path class="bulb__glare" d="M363.977 456.827C364.667 452.176 364.106 447.425 362.352 443.062C360.599 438.699 357.716 434.881 354 432" stroke="white" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
      <path class="bulb__filament" stroke="#000" stroke-width="2" d="M339 437v13.5M343 437v13.5M347 420v24M335 437v13.5M331 420v24"/>
      <g clip-path="url(#clip0)">
        <rect class="bulb__holder" width="40" height="34" x="319" y="394" fill="#C4C4C4" rx="4"/>
        <rect class="bulb__holder-shine" width="20" height="34" x="346" y="394" fill="#F7F7F7"/>
      </g>
      <rect class="bulb__holder-outline" width="38" height="32" x="320" y="395" stroke="#000" stroke-width="2" rx="3"/>
    </g>
  </g>
  <g class="bulb">
    <g class="bulb__bulb">
      <path class="bulb__fake-chord" stroke="red" stroke-width="3" d="M339 411V11"/>
      <circle class="bulb__glass" cx="339" cy="453" r="29" stroke="#000" stroke-width="2"/>
      <circle class="bulb__flash" cx="339" cy="453" r="30" fill="#FAFF13"/>
      <path class="bulb__glare" d="M363.977 456.827C364.667 452.176 364.106 447.425 362.352 443.062C360.599 438.699 357.716 434.881 354 432" stroke="white" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
      <path class="bulb__filament" stroke="#000" stroke-width="2" d="M339 437v13.5M343 437v13.5M347 420v24M335 437v13.5M331 420v24"/>
      <g clip-path="url(#clip0)">
        <rect class="bulb__holder" width="40" height="34" x="319" y="394" fill="#C4C4C4" rx="4"/>
        <rect class="bulb__holder-shine" width="20" height="34" x="346" y="394" fill="#F7F7F7"/>
      </g>
      <rect class="bulb__holder-outline" width="38" height="32" x="320" y="395" stroke="#000" stroke-width="2" rx="3"/>
    </g>
  </g>
  <g class="bulb">
    <path class="bulb__chord" stroke="#C4C4C4" stroke-width="3" d="M339 411V11"/>
    <g class="bulb__bulb">
      <path stroke="none" stroke-width="3" d="M339 411V11"/>
      <circle class="bulb__glass" cx="339" cy="453" r="29" stroke="#000" stroke-width="2"/>
      <circle class="bulb__flash" cx="339" cy="453" r="30" fill="#FAFF13"/>
      <path class="bulb__glare" d="M363.977 456.827C364.667 452.176 364.106 447.425 362.352 443.062C360.599 438.699 357.716 434.881 354 432" stroke="white" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
      <path class="bulb__filament" stroke="#000" stroke-width="2" d="M339 437v13.5M343 437v13.5M347 420v24M335 437v13.5M331 420v24"/>
      <g clip-path="url(#clip0)">
        <rect class="bulb__holder" width="40" height="34" x="319" y="394" fill="#C4C4C4" rx="4"/>
        <rect class="bulb__holder-shine" width="20" height="34" x="346" y="394" fill="#F7F7F7"/>
      </g>
      <rect class="bulb__holder-outline" width="38" height="32" x="320" y="395" stroke="#000" stroke-width="2" rx="3"/>
    </g>
  </g>
  <path class="bulbs__ceiling" stroke="#000" stroke-width="4" d="M109 12h460"/>
  <defs>
    <clipPath id="clip0">
      <rect width="40" height="34" x="319" y="394" rx="4"/>
    </clipPath>
  </defs>
</svg>
              
            
!

CSS

              
                *
  box-sizing border-box

body
  background hsl(210, 40%, 15%)
  display grid
  place-items center
  min-height 100vh

.bulbs
  display none
  height 50vmin
  transform translate(0, -25%)
  overflow visible !important

  &__ceiling
    stroke hsl(210, 40%, 10%)

              
            
!

JS

              
                import gsap from 'https://cdn.skypack.dev/gsap'
const { registerPlugin } = gsap
const { MorphSVGPlugin } = window
registerPlugin(MorphSVGPlugin)

const ROTATION = 20
const LEFT = 'M199.816 386.138C298.5 267 324.5 211 336.624 10.261'
const RIGHT = 'M478.328 386.138C379.644 267 353.644 211 341.52 10.261'
const STRAIGHT = 'M339 411V11'

const COLORS = {
  BULB: 'hsl(55, 100%, 65%)',
  ON: 'hsl(0, 0%, 100%)',
  GLARE: 'hsla(0, 0%, 100%, 0.5)',
  CHORD: 'hsl(0, 0%, 50%)',
  OFF: 'hsl(0, 0%, 60%)',
  HOLDER: 'hsl(0, 0%, 40%)',
  HOLDER_STROKE: 'hsl(0, 0%, 45%)',
}

gsap.defaults({
  ease: 'none',
})

const BULBS = gsap.utils.toArray('.bulb')

gsap.set(BULBS, {
  xPercent: index => -200 + index * 100,
})

gsap.set('.bulb__holder', {
  fill: COLORS.HOLDER,
})
gsap.set('.bulb__holder-outline', {
  stroke: COLORS.HOLDER_STROKE,
})
gsap.set('.bulb__holder-shine', {
  fill: COLORS.GLARE,
})

const BULBERS = [
  BULBS[0].querySelector('.bulb__bulb'),
  BULBS[BULBS.length - 1].querySelector('.bulb__bulb'),
]
const CHORDS = [
  BULBS[0].querySelector('.bulb__chord'),
  BULBS[BULBS.length - 1].querySelector('.bulb__chord'),
]
const GLASSES = gsap.utils.toArray('.bulb__glass')
const FILAMENTS = gsap.utils.toArray('.bulb__filament')
const FLASHES = gsap.utils.toArray('.bulb__flash')

gsap.set([FILAMENTS, GLASSES], {
  stroke: COLORS.OFF,
})

gsap.set(BULBERS[0], {
  rotate: ROTATION,
  transformOrigin: '50% 0%',
})
gsap.set(CHORDS[0], {
  morphSVG: LEFT,
})
gsap.set(FLASHES, {
  scale: 0,
  transformOrigin: '50% 50%',
  fill: COLORS.BULB,
})
gsap.set('.bulb__glare', {
  stroke: COLORS.GLARE,
})

gsap.set(['.bulb__chord', '.bulb__fake-chord'], {
  stroke: COLORS.CHORD,
})

const SWING_SPEED = 0.4
const DELAY = 0.2

const SWING = gsap
  .timeline({
    paused: true,
  })
  .to(BULBERS[0], {
    rotate: 0,
    duration: SWING_SPEED,
  })
  .to(
    CHORDS[0],
    {
      morphSVG: STRAIGHT,
      duration: SWING_SPEED,
    },
    '<'
  )
  .to(BULBERS[1], {
    rotate: -ROTATION,
    duration: SWING_SPEED,
    delay: DELAY,
  })
  .to(
    CHORDS[1],
    {
      duration: SWING_SPEED,
      morphSVG: RIGHT,
    },
    '<'
  )

gsap.set(GLASSES[0], {
  fill: COLORS.BULB,
  stroke: COLORS.ON,
})
gsap.set(FILAMENTS[0], {
  stroke: COLORS.ON,
})
// Swinging is taken care of.
// Then sort out the bulb flashing.
const SWINGER = gsap.to(SWING, {
  totalTime: SWING.duration(),
  repeat: -1,
  yoyo: true,
  duration: 1,
  ease: 'power4.inOut',
})

// Handles flicking the end bulbs on and off.
const FLASHER = gsap
  .timeline({
    repeat: -1,
    yoyo: true,
    duration: 1,
  })
  .set(
    [GLASSES[0], FILAMENTS[0]],
    {
      fill: 'none',
      stroke: COLORS.OFF,
    },
    SWING_SPEED
  )
  .set(
    [GLASSES[GLASSES.length - 1], FILAMENTS[GLASSES.length - 1]],
    {
      fill: COLORS.BULB,
      stroke: COLORS.ON,
    },
    SWING_SPEED + DELAY
  )

// This last one handles the bulbs in the middle.
const OTHERS = GLASSES.filter(
  (g, idx) => idx !== 0 && idx !== GLASSES.length - 1
)
const OTHER_FILAMENTS = FILAMENTS.filter(
  (f, idx) => idx !== 0 && idx !== FILAMENTS.length - 1
)
const OTHER_FLASHES = FLASHES.filter(
  (f, idx) => idx !== 0 && idx !== FLASHES.length - 1
)

// When we go left, make sure it's 1 second
const FLASH_ON = gsap.timeline({
  repeat: -1,
  repeatDelay: 1,
  paused: true,
})
for (let o = 0; o < OTHERS.length; o++) {
  FLASH_ON.to(
    OTHERS[o],
    {
      fill: COLORS.BULB,
      stroke: COLORS.ON,
      repeat: 1,
      yoyo: true,
      duration: DELAY / 3,
    },
    SWING_SPEED + o * (DELAY / 3)
  )
  FLASH_ON.to(
    OTHER_FILAMENTS[o],
    {
      stroke: COLORS.ON,
      repeat: 1,
      yoyo: true,
      duration: DELAY / 3,
    },
    SWING_SPEED + o * (DELAY / 3)
  )
  FLASH_ON.fromTo(
    OTHER_FLASHES[o],
    {
      scale: 0,
      opacity: 1,
    },
    {
      scale: 2,
      opacity: 0,
      duration: 0.2,
    },
    SWING_SPEED + o * (DELAY / 3)
  )
  FLASH_ON.to(
    FLASHES[FLASHES.length - 1],
    {
      scale: 2,
      opacity: 0,
      duration: 0.2,
    },
    SWING_SPEED + DELAY
  )
}
// Flash off is going RTL
const FLASH_OFF = gsap.timeline({
  repeat: -1,
  repeatDelay: 1,
  paused: true,
})
for (let o = OTHERS.length - 1; o >= 0; o--) {
  FLASH_OFF.to(
    OTHERS[o],
    {
      fill: COLORS.BULB,
      stroke: COLORS.ON,
      repeat: 1,
      yoyo: true,
      duration: DELAY / 3,
    },
    SWING_SPEED + (OTHERS.length - o) * (DELAY / 3)
  )
  FLASH_OFF.to(
    OTHER_FILAMENTS[o],
    {
      stroke: COLORS.ON,
      repeat: 1,
      yoyo: true,
      duration: DELAY / 3,
    },
    SWING_SPEED + (OTHERS.length - o) * (DELAY / 3)
  )
  FLASH_OFF.fromTo(
    OTHER_FLASHES[o],
    {
      scale: 0,
      opacity: 1,
    },
    {
      scale: 2,
      opacity: 0,
      duration: 0.2,
    },
    SWING_SPEED + (OTHERS.length - o) * (DELAY / 3)
  )
  FLASH_OFF.to(
    FLASHES[0],
    {
      scale: 2,
      opacity: 0,
      duration: 0.2,
    },
    SWING_SPEED + DELAY
  )
}

const FLASH_LEFT = gsap.to(FLASH_ON, {
  totalTime: 1,
  repeat: -1,
  repeatDelay: 1,
  duration: 1,
})
const FLASH_RIGHT = gsap.to(FLASH_OFF, {
  totalTime: 1,
  repeat: -1,
  repeatDelay: 1,
  duration: 1,
  delay: 1,
})

gsap
  .timeline()
  .add(SWINGER, 0)
  .add(FLASHER, 0)
  .add(FLASH_LEFT, 0)
  .add(FLASH_RIGHT, 0)
  .timeScale(0.9)

gsap.set('.bulbs', {
  display: 'block',
})

              
            
!
999px

Console