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

              
                <main>
	<section>
		<span>JS (GreenSock)</span>
		<button id="face-js" class="face svg-holder" type="button" aria-pressed="false" aria-label="Like">
			I like this
			<div>
				<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
					<defs>
						<clipPath id="mouth-clip">
							<path id="mouth-clip-path" d="M128,166.8 L80,166.8 C77.2,166.8,75,169.1,75,171.8 C75,174.5,77.2,176.8,80,176.8 C82.7,176.8,87,176.8,128,176.8 C168,176.8,173.2,176.8,176,176.8 C178.7,176.8,181,174.5,181,171.8 C181,169,178.7,166.8,176,166.8 Z"/>
						</clipPath>
					</defs>
					<circle id="pop" cx="128" cy="128" r="122" fill="#f2c029"/>
					<circle cx="128" cy="128" r="122" fill="#BBBDBF" stroke="#231F20" stroke-width="8"/>
					<circle opacity="0" id="face" cx="128" cy="128" r="122" fill="#f2c029" stroke="#6b2e0d" stroke-width="8"/>
					<circle id="cheek-r" opacity="0" fill="#E8393C" cx="205.9" cy="151.1" r="25"/>
					<circle id="cheek-l" opacity="0" fill="#E8393C" cx="48.9" cy="151.1" r="25"/>
					<ellipse id="eye-r" cx="168.4" cy="104" fill="#231F20" rx="12.9" ry="18.8"/>
					<ellipse id="eye-l" cx="87.6" cy="104" fill="#231F20" rx="12.9" ry="18.8"/>
					<path id="heart-l" opacity="0" fill="#BD1A1A" d="M71.5 81.6c-16.6-21.1-41.9-7.5-38.1 14.3 3.2 17.9 23.7 31.9 47.6 39.6 19.9-15.4 34.3-35.6 31.2-53.5-3.9-21.8-32.3-25.9-40.7-.4z"/>
					<path id="heart-r" opacity="0" fill="#BD1A1A" d="M185.1 81.6c-8.4-25.5-36.8-21.4-40.7.4-3.2 17.9 11.3 38.1 31.2 53.5 23.9-7.6 44.4-21.7 47.6-39.6 3.9-21.8-21.4-35.4-38.1-14.3z"/>
					<path id="mouth" fill="#231F20" d="M128,166.8 L80,166.8 C77.2,166.8,75,169.1,75,171.8 C75,174.5,77.2,176.8,80,176.8 C82.7,176.8,87,176.8,128,176.8 C168,176.8,173.2,176.8,176,176.8 C178.7,176.8,181,174.5,181,171.8 C181,169,178.7,166.8,176,166.8 Z"/>
					<g clip-path="url(#mouth-clip)">
						<ellipse id="tongue" fill="#AD1212" cx="128" cy="209.3" rx="40" ry="27.5"/>
					</g>
				</svg>
			</div>
		</button>
	</section>
	<section>
		<span>CSS</span>
		<button id="face-css" class="face svg-holder" type="button" aria-pressed="false" aria-label="Like">
			I like this
			<div>
				<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
					<defs>
						<clipPath id="mouth-clip-2">
							<path id="mouth-clip-path-2" d="M128,166.8 L80,166.8 C77.2,166.8,75,169.1,75,171.8 C75,174.5,77.2,176.8,80,176.8 C82.7,176.8,87,176.8,128,176.8 C168,176.8,173.2,176.8,176,176.8 C178.7,176.8,181,174.5,181,171.8 C181,169,178.7,166.8,176,166.8 Z"/>
						</clipPath>
					</defs>
					<circle id="pop-2" cx="128" cy="128" r="122" fill="#f2c029"/>
					<circle cx="128" cy="128" r="122" fill="#BBBDBF" stroke="#231F20" stroke-width="8"/>
					<circle opacity="0" id="face-2" cx="128" cy="128" r="122" fill="#f2c029" stroke="#6b2e0d" stroke-width="8"/>
					<circle id="cheek-r-2" opacity="0" fill="#E8393C" cx="205.9" cy="151.1" r="25"/>
					<circle id="cheek-l-2" opacity="0" fill="#E8393C" cx="48.9" cy="151.1" r="25"/>
					<ellipse id="eye-r-2" cx="168.4" cy="104" fill="#231F20" rx="12.9" ry="18.8"/>
					<ellipse id="eye-l-2" cx="87.6" cy="104" fill="#231F20" rx="12.9" ry="18.8"/>
					<path id="heart-l-2" opacity="0" fill="#BD1A1A" d="M71.5 81.6c-16.6-21.1-41.9-7.5-38.1 14.3 3.2 17.9 23.7 31.9 47.6 39.6 19.9-15.4 34.3-35.6 31.2-53.5-3.9-21.8-32.3-25.9-40.7-.4z"/>
					<path id="heart-r-2" opacity="0" fill="#BD1A1A" d="M185.1 81.6c-8.4-25.5-36.8-21.4-40.7.4-3.2 17.9 11.3 38.1 31.2 53.5 23.9-7.6 44.4-21.7 47.6-39.6 3.9-21.8-21.4-35.4-38.1-14.3z"/>
					<path id="mouth-2" fill="#231F20" d="M128,166.8 L80,166.8 C77.2,166.8,75,169.1,75,171.8 C75,174.5,77.2,176.8,80,176.8 C82.7,176.8,87,176.8,128,176.8 C168,176.8,173.2,176.8,176,176.8 C178.7,176.8,181,174.5,181,171.8 C181,169,178.7,166.8,176,166.8 Z"/>
					<g clip-path="url(#mouth-clip-2)">
						<ellipse id="tongue-2" fill="#AD1212" cx="128" cy="209.3" rx="40" ry="27.5"/>
					</g>
				</svg>
			</div>
		</button>
	</section>
</main>
              
            
!

CSS

              
                /* animation stuff */
$mouth-like-path: "M128,151.1 L75,151.1 C71.9,151.1,68.2,152.6,68,157.6 C67.8,161,69.2,165,69.8,166.5 C71.3,171,90,206.1,128,206.2 C167.2,206.2,185.3,169.7,186.6,165.4 C187.3,162.6,188.1,160.3,188,157.6 C187.8,153.6,181.4,151.1,181.4,151.1 Z";
$heart-out-ease: cubic-bezier(.45,-0.3,1,.2);
$heart-in-ease: cubic-bezier(0,.8,.53,1.3);

#face-css {
	svg {
		#pop-2 {
			opacity: .5;
			transform-origin: 50% 50%; transform: scale(1);
		}
		#face-2 {transition: opacity .2s linear; transition-delay: .3s;}
		#mouth-2, #mouth-clip-path-2 {transition: d .3s ease; transition-delay: .3s;}
		#tongue-2 {
			transform: translate(0px,30px);
			transition: transform .3s ease-out; transition-delay: .2s;
		}
		#heart-l-2 {
			opacity: 1; 
			transform-origin: 72px 100px; 
			transform: scale(0) rotate(10deg);
			transition: transform .3s $heart-out-ease; transition-delay: .1s;
		}
		#heart-r-2 {
			opacity: 1; 
			transform-origin: 183px 100px; 
			transform: scale(0) rotate(-10deg);
			transition: transform .3s $heart-out-ease; transition-delay: 0s;
		}
		#cheek-l-2, #cheek-r-2 {transition: opacity .4s linear;}
	}
	
}
#face-css[aria-pressed="true"] {
	svg {
		#pop-2 {
			opacity: 0;
			transform: scale(1.4); transition: transform .3s ease-out, opacity .3s linear;
		}
		#face-2 {opacity: 1; transition-delay: 0s;}
		#mouth-2, #mouth-clip-path-2 {d: path($mouth-like-path); transition-delay: 0s;}
		#tongue-2 {transform: translate(0px,0px); transition-delay: 0s;}
		#heart-l-2, #heart-r-2 {
			transform: scale(1.25) rotate(0deg);
			transition: transform .3s $heart-in-ease;
		}
		#heart-l-2 {transition-delay: 0s;}
		#heart-r-2 {transition-delay: .1s;}
		#cheek-l-2, #cheek-r-2 {opacity: .2;}
	}
}



/* layout stuff */
main {
	margin: 0; padding: 3em;
	width: 100%; height: 100vh;
	box-sizing: border-box;
	display: flex; flex-flow: row wrap;
	justify-content: space-around; align-items: center; align-content: center;
	section {
		margin: 2em 1em;
		flex: 1 1 auto; position: relative;
		min-width: 8em; max-width: 24em;
		span {
			margin: 0 0 1em; padding: 1em 0;
			display: block; width: 100%;
			font-family: 'Helvetica', sans-serif; font-size: 1em; line-height: 100%; font-weight: bold; text-align: center;
			position: absolute; top: 0; left: 50%; transform: translate(-50%, calc(-100% - 0em));
		}
		button {
			padding: 0;
			display: block; position: relative;
			width: 100%;
			border: none; background: none;
			font-size: 0;
			transform: scale(1);
			transition: transform .15s ease-out;
			&::before {
				content: "";
				width: calc(100% - 5px); height: calc(100% - 5px);
				display: block;
				background: none; border-radius: 50%;
				position: absolute; top: 50%; left: 50%; z-index: 0;
				transform: translate(-50%,-50%);
				box-shadow: 0 5px 30px 0px rgba(0,0,0,0.5);
				opacity: 0;
				transition: opacity .15s ease-out;
			}
			&:focus {
				outline: none;
			}
			&:hover, &:focus {
				transform: scale(1.1);
				&::before {opacity: 1;}
			}
		}
	}
}

.svg-holder {
	div {
		position: relative;
		width: 100%; height: 0;
		padding-bottom: 100%;
		pointer-events: none;
		svg {
			position: absolute; top: 0; left: 0;
			width: 100%; height: 100%;
			overflow: visible;
			pointer-events: none;
		}
	}
}
              
            
!

JS

              
                var faceJs = document.getElementById('face-js');
var face = document.getElementById('face');
var pop = document.getElementById('pop');
var mouth = document.getElementById('mouth');
var mouthClipPath = document.getElementById('mouth-clip-path');
var tongue = document.getElementById('tongue');
var eyeL = document.getElementById('eye-l');
var eyeR = document.getElementById('eye-r');
var heartL = document.getElementById('heart-l');
var heartR = document.getElementById('heart-r');
var cheekL = document.getElementById('cheek-l');
var cheekR = document.getElementById('cheek-r');
var mouthLike = "M128,151.1 L75,151.1 C71.9,151.1,68.2,152.6,68,157.6 C67.8,161,69.2,165,69.8,166.5 C71.3,171,90,206.1,128,206.2 C167.2,206.2,185.3,169.7,186.6,165.4 C187.3,162.6,188.1,160.3,188,157.6 C187.8,153.6,181.4,151.1,181.4,151.1 Z";
var faceStatus = false;

// set some initial properties
TweenMax.set(heartL, {opacity: 1, scale: 0, rotation: "10deg", transformOrigin: "50% 50%"});
TweenMax.set(heartR, {opacity: 1, scale: 0, rotation: "-10deg", transformOrigin: "50% 50%"});
TweenMax.set(tongue, {y: 30});
TweenMax.set(pop, {opacity: .5, transformOrigin: "50% 50%"});

// create timeline
var faceTl = new TimelineMax({paused: true});
faceTl
	// fade in face background
	.to(face, .2, {opacity: 1, ease: Linear.easeNone}, "0")

	// morph mouth to smile
	.to([mouth, mouthClipPath], .3, {morphSVG: mouthLike, ease: Power2.easeOut}, "0")

	// move tongue up
	.to(tongue, .3, {y: 0, ease: Power2.easeOut}, "0")

	// bring heart eyes in, with slight delay on the right one
	.to([heartL, heartR], .3, {rotation: "0deg", ease: Power1.easeOut}, "0")
	.to(heartL, .3, {scale: 1.25, ease: CustomEase.create("custom", "M0,0 C0.076,0.15 0.15,1.111 0.71,1.112 0.876,1.112 0.832,1 1,1")}, "0")
	.to(heartR, .3, {scale: 1.25, ease: CustomEase.create("custom", "M0,0 C0.076,0.15 0.15,1.111 0.71,1.112 0.876,1.112 0.832,1 1,1")}, ".1")
	
	// fade cheeks in
	.to([cheekL, cheekR], .4, {opacity: .2, ease: Linear.easeNone}, "0")
;

// event handlers
faceJs.addEventListener('click', onFaceJsClick);	

// on click
function onFaceJsClick(e) {
	let el = e.target;
	let pressed = el.getAttribute('aria-pressed');
	
	// face is on
	if(pressed === 'true') {
		// set aria state
		el.setAttribute('aria-pressed', false);
		// play the timeline backward
		faceTl.reverse();
	// face is off
	} else {
		// set aria state
		el.setAttribute('aria-pressed', true);
		// play the timeline forward
		faceTl.play();
		// play background pop effect
		TweenMax.fromTo(pop, .3, {scale: 1, opacity: .5}, {scale: 1.4, opacity: 0, ease: Power1.easeOut})
	}
	console.log("pressed");
}





/* functionality to add/remove class for CSS version */

var faceCss = document.getElementById('face-css');
var faceStatusCss = false;

// click handler
faceCss.addEventListener('click', onFaceCssClick);

// on click
function onFaceCssClick(e) {
	let el = e.target;
	let pressed = el.getAttribute('aria-pressed');
	
	// face is on
	if(pressed === 'true') {
		// set aria state
		el.setAttribute('aria-pressed', false);
	// face is off
	} else {
		// set aria state
		el.setAttribute('aria-pressed', true);
	}
}
              
            
!
999px

Console