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

              
                - const COUNT = 360 / 6
mixin button(className)
  button.button(class=className)
    span.button__text Love
    span.button__icon
      span.heart__particles
        - let p = 0
        while p < COUNT
          span.heart__particle
          - p++
      svg.heart.heart--stroke(viewBox="0 0 24 24")
        path(d="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z")
      svg.heart.heart--fill(viewBox="0 0 24 24")
        path(d="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z")

+button('button--primary')
+button('button--secondary')
              
            
!

CSS

              
                *
  box-sizing border-box

body
  min-height 100vh
  display flex
  align-items center
  justify-content center
  background hsl(0, 0%, 98%)

  & > * + *
    margin-right 24px

:root
  --transition 0.3
  --heart-fill hsl(10, 80%, 50%)

.heart
  height 100%
  width 100%
  position absolute

  &--stroke
    stroke var(--heart-stroke)
    stroke-width 2.5px
    fill none

  &--fill
    stroke none
    fill var(--heart-fill)
    transform scale(var(--scale, 0))

  &__particle
    height 16px
    width 16px
    position absolute
    top 50%
    left 50%
    border-radius 50%
    background 'hsl(%s, 80%, 70%)' % var(--h)
    transform translate(-50%, -50%) rotate(calc(var(--r, 0) * 1deg)) translate(0, calc(var(--radius, 0) * 1px)) scale(0)


.button
  height 40px
  border 0
  cursor pointer
  border-radius 6px
  position relative
  display flex
  align-items center
  justify-content center
  width 100px
  font-family sans-serif
  text-align left
  outline transparent
  color var(--stroke)
  background var(--fill)
  background 'hsl(%s, %s, %s)' % (var(--hue) calc(var(--saturation) * 1%) calc(var(--lightness) * 1%))
  box-shadow 2px 4px 4px hsla(0, 0%, 10%, 0.5)
  transition box-shadow 0.2s, background 0.2s

  &--primary
    --hue 260
    --saturation 50
    --lightness 20
    --stroke hsl(0, 0%, 100%)
    --heart-stroke hsl(0, 0%, 100%)
    margin-right 24px

  &--secondary
    --hue 0
    --saturation 0
    --lightness 100
    --stroke hsl(0, 0%, 40%)
    --heart-stroke hsl(0, 0%, 60%)


  &__text
    margin-right 6px
    opacity var(--opacity)

  &__icon
    position relative
    height 24px
    width 24px

  &:hover
    --scale 0.3
    background 'hsl(%s, %s, %s)' % (var(--hue) calc(var(--saturation) * 1%) calc(var(--lightness) * 0.96%))
    box-shadow 2px 2px 4px hsla(0, 0%, 10%, 0.5)
    .heart--fill
      transition transform calc(var(--transition) * 1s) cubic-bezier(.7,.9,.6,2.5)

  &:active
    background 'hsl(%s, %s, %s)' % (var(--hue) calc(var(--saturation) * 1%) calc(var(--lightness) * 0.92%))
    box-shadow 0 0 0 hsla(0, 0%, 10%, 0.5)

  &--active
  &--active:hover
    --scale 0.94
    --opacity 0.25


    .heart--fill
      transition transform calc(var(--transition) * 1s) cubic-bezier(.7,.9,.6,2.5)

    .button__text
      transition opacity 0.1s

    .heart__particle
      opacity 0
      transform translate(-50%, -50%) rotate(calc(var(--r, 0) * 1deg)) translate(0, calc(var(--d, 0) * 1px)) scale(var(--s))
      transition transform calc(var(--t) * 1.25s) calc(var(--transition) * 0.5s), opacity calc(var(--transition) * 0.25s) calc(var(--t) * 1.25s)
              
            
!

JS

              
                const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
const COUNT = 360 / 6;
const BTN = document.querySelectorAll(".button");

const setParticles = b => {
  const PARTICLES = b.querySelectorAll('.heart__particle')
  PARTICLES.forEach((particle, index) => {
    const CHARACTER = {
      "--d": random(30, 60),
      "--r": (360 / 25) * index,
      "--h": random(0, 360),
      "--t": random(25, 50) / 100,
      "--s": random(20, 60) / 100
    };
    particle.setAttribute(
      "style",
      JSON.stringify(CHARACTER)
        .replace(/,/g, ";")
        .substring(1, JSON.stringify(CHARACTER).length - 1)
        .replace(/"/g, "")
    );        
  })
}


BTN.forEach((b) => {
  setParticles(b)
  b.addEventListener("click", () => {
    b.classList.toggle('button--active')
    if (b.classList.contains('button--active')) setParticles(b)
  })
});



              
            
!
999px

Console