Skip to content

Instantly share code, notes, and snippets.

@Rplus
Last active March 11, 2016 07:04
Show Gist options
  • Save Rplus/6cd08bb80ae0804216d0 to your computer and use it in GitHub Desktop.
Save Rplus/6cd08bb80ae0804216d0 to your computer and use it in GitHub Desktop.
[Codepen] Micro Animation of Like
<!DOCTYPE html>
html(lang="en")
head
meta(charset="UTF-8")
title Micro Animation of Like
meta(name="viewport", content="width=device-width")
link(rel="stylesheet", href="style.css")
body
h1.intro Micro Animation of Like
small click ♥ to see animation
mixin icon($icon)
svg.icon
use(xlink:href="#icon-#{$icon}")
.box
.mobile
main.m-body
section.section.content
figure
img(src="http://p-hold.com/tree/480/200", width="480", height="200")
figcaption Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni, rerum.
section.section.reaction-bar
input#ip-heart(type="checkbox").ip-heart.sr-only
label.heart-count(for="ip-heart", style="counter-reset: heart-counter 120;")
.heart-icon
+icon('heart')
+icon('heart')
+icon('heart')
+icon('heart')
ul.avatars
- var i = 7;
while (i--)
li.avatar(style="background-image: url('http://lorempixel.com/image_output/people-q-c-60-60-#{i + 4}.jpg')")
.comment-count
+icon('comment')
| 24
ul.section.comments
li
a(href="###") Elva White
| hey, really stunning photos here!
footer.m-footer
a.footer-link friends
a.footer-link chats
a.footer-link.is-active feed
a.footer-link more
svg(xmlns="http://www.w3.org/2000/svg").sr-only
symbol#icon-heart(viewbox='0 0 24 32')
path(d='M12 27c12.469-9.813 12-13.281 12-16s-2.25-6-6-6-6 4-6 4-2.25-4-6-4-6 3.281-6 6-0.469 6.188 12 16z')
symbol#icon-comment(viewbox='0 0 28 32')
path(d='M24 4h-20c-1.938 0-4 2-4 4v12c0 4 4 4 4 4h2v8l8-8c0 0 8.063 0 10 0s4-2.125 4-4v-12c0-1.938-2-4-4-4z')
blockquote.info
| inspired from: #[a(href="https://dribbble.com/shots/2522985-Micro-Animation-of-Like-Principle-Freebie") Micro Animation of Like] by #[a(href="https://dribbble.com/privetwagner") Roman Wagner]
$c-white: #fff;
$c-black: #000;
$c-red: #f94e34;
$c-mbody: #fffff7;
$c-count-bgc: #f2f2f2;
$c-mobile-bgc: #f0f0f0;
$c-footer: #352839;
$c-svg: #d1d7d7;
$h-footer: 4em;
$avatar-limit: 4;
$avatar-size: 2.5em;
$avatar-overlay-ratio: 2 / 3;
.m-body {
height: 100%;
overflow: auto;
margin-left: .75em;
margin-right: .75em;
padding-left: .75em;
padding-right: .75em;
padding-bottom: $h-footer;
border-left: 1px solid rgba($c-black, .15);
border-right: 1px solid rgba($c-black, .15);
background-color: $c-mbody;
img {
width: 100%;
}
.section {
padding-top: 1em;
padding-bottom: 1em;
border-top: 1px solid rgba($c-black, .1);
}
.icon {
width: 1.5em;
height: 1.5em;
margin-right: .25em;
fill: $c-svg;
}
.icon-comment {
transform: rotateY(180deg);
}
}
.content {
margin-bottom: .5em;
}
.reaction-bar {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
color: #999;
}
.heart-count,
.comment-count {
display: inline-flex;
align-items: center;
background-color: $c-count-bgc;
padding: .5em 1em;
border-radius: 10em;
cursor: pointer;
transition: background-color .3s;
-webkit-tap-highlight-color: rgba($c-white, 0);
&:active {
background-color: rgba($c-count-bgc, .5);
}
}
.heart-count {
&::after {
content: counter(heart-counter);
}
.ip-heart:checked ~ & {
counter-increment: heart-counter 1;
}
}
.heart-icon {
position: relative;
.icon + .icon {
position: absolute;
top: 0;
left: 0;
fill: $c-red;
transition: .2s;
opacity: 0;
}
.icon:nth-of-type(2) {
transform: scale(2);
opacity: 0;
}
}
@keyframes heart-path {
0% { transform: translate3d(0,0,0) rotate(0deg) scale(.33); opacity: 1;}
30% { transform: translate3d(-20%,-10%,0) rotate(20deg) scale(.33);}
50% { opacity: 1;}
100% { transform: translate3d(-50%,-50%,0) rotate(40deg) scale(.33); opacity: 0;}
}
@keyframes heart-path-2 {
0% { transform: translate3d(0,0,0) rotate(0deg) scale(.33); opacity: 1;}
30% { transform: translate3d(20%,-10%,0) rotate(-20deg) scale(.33);}
50% { opacity: 1;}
100% { transform: translate3d(50%,-50%,0) rotate(-40deg) scale(.33); opacity: 0;}
}
.ip-heart:checked ~ .heart-count {
.icon:nth-of-type(2) {
transform: none;
opacity: 1;
}
.icon:nth-of-type(3) {
animation: heart-path .48s;
}
.icon:nth-of-type(4) {
animation: heart-path-2 .48s;
}
}
.comment-count .icon {
transform: rotateY(180deg);
}
.avatars {
position: relative;
min-height: $avatar-size;
margin-left: .25em;
margin-right: auto;
padding: 0;
list-style-type: none;
}
.avatar {
position: absolute;
top: 0;
left: $avatar-size * ($avatar-limit - 1) * $avatar-overlay-ratio;
width: $avatar-size;
height: $avatar-size;
border: ($avatar-size / 12) solid $c-mbody;
border-radius: 50%;
background: no-repeat 50% / cover;
transform-origin: 100% 50%;
transition: .3s;
opacity: 0;
transform: scale(.3);
@for $i from 2 through ($avatar-limit + 1) {
&:nth-of-type(#{$i}) {
left: $avatar-size * ($i - 2) * $avatar-overlay-ratio;
z-index: $avatar-limit*2 - $i;
transform: none;
opacity: 1;
}
}
&:nth-of-type(1) {
left: 0;
z-index: $avatar-limit*2;
transform: scale(.1);
transform-origin: 0% 50%;
opacity: .5;
visibility: hidden;
}
.ip-heart:checked ~ .avatars & {
&:nth-of-type(1) {
transform: none;
opacity: 1;
visibility: visible;
}
@for $i from 2 through ($avatar-limit) {
&:nth-of-type(#{$i}) {
transition-delay: .05s * $i;
transform: translateX($avatar-size * $avatar-overlay-ratio);
}
}
&:nth-of-type(#{$avatar-limit + 1}) {
transition-delay: .05s * ($avatar-limit + 1);
transform: translateX($avatar-size * $avatar-overlay-ratio / 4) scale(.3);
opacity: 0;
}
}
}
.comments {
list-style-type: none;
padding-left: 0;
a {
color: #bc82c5;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
}
.m-footer {
position: absolute;
bottom: 0;
z-index: 100;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
min-height: $h-footer;
background-color: $c-footer;
text-transform: capitalize;
text-align: center;
font-size: 14px;
}
.footer-link {
flex: 1;
padding-top: .5em;
padding-bottom: .5em;
color: $c-white;
opacity: .5;
cursor: pointer;
transition: opacity .3s;
&:hover,
&.is-active {
opacity: 1;
}
svg {
display: block;
margin: 0 auto;
fill: currentColor;
width: 2em;
height: 2em;
}
}
.mobile {
position: relative;
width: 30em;
height: 30em;
margin: 0 auto;
border: 2px solid $c-black;
background-color: $c-mobile-bgc;
font-family: sans-serif;
line-height: 1.5;
&::before {
content: '';
position: absolute;
top: -2px;
left: -.5em;
right: -.5em;
bottom: -8em;
z-index: -1;
background-color: $c-black;
border-radius: 0 0 2em 2em;
}
&::after {
content: '';
position: absolute;
left: 50%;
top: calc(100% + 4em);
z-index: -1;
transform: translateX(-50%) translateY(-50%);
width: 5em;
height: 5em;
border: .5em double rgba(#fff, .2);
border-radius: 50%;
}
}
.box {
flex: 1;
width: 100%;
max-width: 40rem;
margin: 0 auto;
}
/// reset
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
}
html {
height: 100%;
}
body {
display: flex;
flex-direction: column;
min-height: 100%;
margin: 0;
background: linear-gradient(#ffe, #fff 90%) no-repeat fixed;
color: #222;
}
.intro {
width: 90%;
max-width: 30rem;
padding-bottom: 1rem;
margin: 0 auto 1em;
padding-top: .5em;
font-size: calc(1rem + 2vmin);
text-transform: capitalize;
border-bottom: 1px dashed rgba(#000, .3);
text-align: center;
small {
display: block;
opacity: .5;
font-style: italic;
text-transform: none;
}
}
.info {
margin: 0;
padding: 1em;
font-size: .9em;
font-style: italic;
font-family: serif;
text-align: right;
opacity: .5;
a {
color: inherit;
}
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;
}
@Rplus
Copy link
Author

Rplus commented Mar 10, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment