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

              
                <a href="#" class="like-button">
  <svg class="heart-icon stroke" viewBox="0 0 24 24">
    <defs>
      <clipPath id="mask">
        <path d="M12 4.435c-1.989-5.399-12-4.597-12 3.568 0 4.068 3.06 9.481 12 14.997 8.94-5.516 12-10.929 12-14.997 0-8.118-10-8.999-12-3.568z"/>
      </clipPath>
    </defs>
    <circle id="first-stroke" r="0" cx="12" cy="12" clip-path="url(#mask)"></circle>
    <circle id="second-stroke" r="0" cx="12" cy="12" clip-path="url(#mask)"></circle>
  </svg>
  <svg class="heart-icon red" viewBox="0 0 24 24">
    <path d="M12 4.435c-1.989-5.399-12-4.597-12 3.568 0 4.068 3.06 9.481 12 14.997 8.94-5.516 12-10.929 12-14.997 0-8.118-10-8.999-12-3.568z"/>
  </svg>
  <svg class="heart-icon" viewBox="0 0 24 24">
    <path d="M12 4.435c-1.989-5.399-12-4.597-12 3.568 0 4.068 3.06 9.481 12 14.997 8.94-5.516 12-10.929 12-14.997 0-8.118-10-8.999-12-3.568z"/>
  </svg>
</a>

<div class="text">
  <h1>Daily UI #2 - Twitter like button</h1>
  <p>from <a href="https://dribbble.com/shots/2609982-Twitter-like-button" target="_blank">Twitter like button by Arjun Kani</a></p>
  <p>by <a href="https://twitter.com/Alex_Toudic" target="_blank">@Alex_Toudic</a></p>
</div>
              
            
!

CSS

              
                $background = #2a2f34
$mainColor  = #e01f4f

body,
html {
  width: 100%
  height: 100%
}


body {
  position: relative
  
  background: $background
}

.text {
  position: absolute
  bottom: 20px
  left: 20px
  
  font-family: Inconsolata
  color: white
  
  line-height: 1.2em
  
  h1 {
    text-transform: uppercase
  }
  
  a {
    text-decoration: none
    
    color: $mainColor
    
    transition: color 0.4s
    
    &:hover {
      color: lighten($mainColor, 50%)
    }
  }
}

.like-button {
  position: absolute
  top: 50%
  left: 50%
  
  transform: translate(-50%, -50%)
}

.heart-icon {
  width: 24px
  height: 24px
  
  fill: #a9aeb3
  
  &.red {
    position: absolute
    top: 0
    left: 0
    
    fill: $mainColor
    
    transform: scale(0)
  }
  
  &.stroke {
    position: absolute
    top: 0
    left: 0
    
    circle {
      fill: none
      stroke: #e0e2e4
      stroke-width: 2
    }
  }
}
              
            
!

JS

              
                let liked = false

const colors = {
  yellow: '#fde36d',
  blue: '#97e8f5',
  orange: '#fd706a',
  purple: '#ba7fdd',
  green: '#85f981'
}

const likeButton = document.querySelector('.like-button')

const likeTimeline = new mojs.Timeline()

const firstStroke = document.querySelector('#first-stroke')
const secondStroke = document.querySelector('#second-stroke')

const delay = 0.5,
      from = 5,
      to = 15
const stroke = new mojs.Tween({
		duration : 400,
    easing: 'expo.out',
		onUpdate: progress => {
			firstStroke.setAttribute('r', (progress/(1-delay)) * (to - from) + from)
      secondStroke.setAttribute('r', (Math.max(progress-delay, 0)/(1-delay)) * (to - from) + from)
		}
	})

const redHeart = document.querySelector('.heart-icon.red')
const scale = new mojs.Tween({
		duration: 400,
    delay: 250,
		onUpdate: progress => {
      bounceProgress = mojs.easing.elastic.out(1.005*progress-0.005)
			redHeart.style.transform = `scale3d(${bounceProgress}, ${bounceProgress}, 1)`
		}
	})

const burst = new mojs.Burst({
		parent: likeButton,
    delay: 350,
		duration: 600,
		shape : 'circle',
		x: '50%',
		y: '50%',
		opacity: 1,
		childOptions: { 
      radius: {5:0},
      type: 'line',
      stroke: [colors.yellow, colors.blue],
      strokeWidth: 2
    },
    radius: {25:40},
		count: 6,
		isSwirl: true,
    swirlSize: 20,
		isRunLess: true,
		easing: mojs.easing.bezier(0.1, 1, 0.3, 1)
	})

const burst2 = new mojs.Burst({
		parent: likeButton,
    delay: 400,
		duration: 600,
		shape : 'circle',
		x: '50%',
		y: '50%',
		opacity: 1,
		childOptions: { 
      radius: {5:0},
      type: 'line',
      stroke: [colors.orange, colors.purple, colors.blue],
      strokeWidth: 2
    },
    radius: {25:50},
		count: 6,
    angle: 25,
		isSwirl: true,
    swirlSize: 20,
		isRunLess: true,
		easing: mojs.easing.bezier(0.1, 1, 0.3, 1)
	})

const burst3 = new mojs.Burst({
		parent: likeButton,
    delay: 500,
		duration: 600,
		shape : 'circle',
    fill: colors.green,
		x: '50%',
		y: '50%',
		opacity: 1,
    radius: {20:30},
    childOptions: { 
        radius: {2:0}
    },
		count: 6,
		isRunLess: true,
		easing: mojs.easing.bezier(0.1, 1, 0.3, 1)
	})

likeTimeline.add(stroke, scale, burst, burst2, burst3)

const reset = () => {
  redHeart.style.transform = `scale3d(0, 0, 1)`
}

const toggleLike = e => {
  e.preventDefault()
  
  liked = !liked
  
  if (liked) likeTimeline.start()
  else reset()
}
likeButton.addEventListener('click', toggleLike)
likeButton.addEventListener('touchstart', toggleLike)
              
            
!
999px

Console