HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<main>
<section class="header">
<div class="title">My App Name</div>
</section>
<section class="content">
<div class="card1 card-container">
<div class="ripple-container">
<div class="ripple"></div>
</div>
<div class="card">
<div class="card-header">
<div class="title">Card 1</div>
<div class="items-inline">
<div class="icon-button expand-button">
<i class="material-icons icon">fullscreen</i>
</div>
<div class="icon-button close-button">
<i class="material-icons icon">close</i>
</div>
</div>
</div>
<div class="card-text">
Lorem ipsum dolor sit amet, id pri eros probo aeque, eos summo vitae lucilius ad, ea vim tale stet delectus. Viris feugiat inermis ius eu, sed an esse commune percipitur. Meis efficiendi eum in, mea at copiosae verterem. Vim no omittam mentitum principes.
Mei in magna recteque ocurreret, abhorreant definitionem an qui.
</div>
<div class="card-footer">
<div class="icon-button back-button">
<i class="material-icons icon">arrow_back</i>
</div>
<div class="btn" style="text-align: center">Animate to Box Below</div>
<div class="icon-button forward-button">
<i class="material-icons icon">arrow_forward</i>
</div>
</div>
</div>
</div>
<div class="card2 card-container">
<div class="ripple-container">
<div class="ripple"></div>
</div>
<div class="card">
<div class="card-header">
<div class="title">Card 2</div>
<div class="items-inline">
<div class="icon-button expand-button">
<i class="material-icons icon">fullscreen</i>
</div>
<div class="icon-button close-button">
<i class="material-icons icon">close</i>
</div>
</div>
</div>
<div class="card-text">
Some text
</div>
<div class="card-footer">
<div class="icon-button back-button">
<i class="material-icons icon">arrow_back</i>
</div>
<div class="btn" style="text-align: center">Animate to Box Above</div>
<div class="icon-button forward-button">
<i class="material-icons icon">arrow_forward</i>
</div>
</div>
</div>
</div>
<div class="circle-container">
<div class="circle">
<i class="material-icons icon">add</i>
</div>
</div>
</section>
<section class="footer">
<div class="title">Material Design Motion with GSAP</div>
</section>
</main>
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
min-height: 100%;
background: #eee;
}
main {
height: 100vh;
display: flex;
flex-direction: column;
position: relative;
opacity: 0;
}
.header {
width: 100%;
height: 56px;
background: #1F2B49;
display: flex;
align-items: center;
box-shadow: 0 1px 3px rgba(0,0,0,.2), 0 1px 1px rgba(0,0,0,.14), 0 2px 1px -1px rgba(0,0,0,.12);
}
.header .title {
padding: 0 16px 0 16px;
color: rgba(255, 255, 255, 0.87);
padding: 0 16px 0 16px;
}
.content {
padding: 16px;
position: relative;
flex: 1;
}
.footer {
height: 56px;
width: 100%;
background: #171E33;
display: flex;
align-items: center;
}
.footer .title {
padding: 0 16px 0 16px;
color: rgba(255, 255, 255, 0.7);
}
.card-container {
min-height: 150px;
max-height: 40vh;
overflow: hidden;
position: relative;
border-radius: 2px;
margin-bottom: 16px;
}
.card1 {
height: 300px;
border: dashed 1px red;
}
.card2 {
height: 200px;
border: dashed 1px blue;
}
.card {
height: 100%;
color: #fff;
display: flex;
flex-direction: column;
border-radius: 2px;
visibility: hidden;
opacity: 0;
}
.card-header {
height: 56px;
width: 100%;
display: flex;
align-items: center;
}
.items-inline {
display: flex;
align-items: center;
}
.card-footer {
height: 72px;
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px;
}
.card-header .title {
flex: 1;
padding: 0 16px 0 16px;
}
.card-header .close-button {
padding: 16px;
cursor: pointer;
}
.card-text {
width: 100%;
flex: 1;
padding: 16px;
color: rgba(255,255,255, 0.54);
}
.icon-button {
cursor: pointer;
}
.btn {
background-color: #6CBC35;
height: 48px;
border-radius: 2px;
padding: 16px 32px 16px 32px;
diplay: flex;
align-items: center;
cursor: pointer;
}
.btn-raised {
box-shadow: 0 1px 5px rgba(0, 0, 0, .2), 0 2px 2px rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .12);
}
.circle-container,
.ripple-container {
position: absolute;
width: 72px;
height: 72px;
}
.circle-container {
top: calc(100% - 72px);
// left: 0;
// margin: -16px 0 0 16px;
left: calc(100% - 72px);
margin: -16px;
}
.ripple-container {
border-radius: 2px;
top: 0;
left: 0;
}
.circle,
.ripple {
position: absolute;
width: 72px;
height: 72px;
top: 50%;
left: 50%;
border-radius: 50%;
cursor: pointer;
background: #1167A0;
}
.ripple {
visibility: hidden;
}
.circle {
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 1px 5px rgba(0,0,0,.2), 0 2px 2px rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.12);
}
.circle i {
color: #fff;
}
console.clear();
var log = console.log.bind(console);
var kappa = 0.551915024494;
var cardNum = 1; //Change number to switch cards (1 or 2)
var cardContainer = document.querySelector(".card" + cardNum);
var circleContainer = document.querySelector(".circle-container");
var rippleContainer = cardContainer.querySelector(".ripple-container");
var circle = document.querySelector(".circle");
var circleIcon = circle.querySelector("i");
var ripple = cardContainer.querySelector(".ripple");
var card = cardContainer.querySelector(".card");
var closeButton = cardContainer.querySelector(".close-button");
var root = document.documentElement;
var body = document.body;
var cardStyle = {
background: '#1167A0',
boxShadow: '0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2)'
};
var p0 = { x: 0, y: 0 };
var p1 = { x: 0, y: 0 };
var p2 = { x: 0, y: 0 };
var p3 = { x: 0, y: 0 };
var bezier = { values: [p0, p1, p2, p3], type: "cubic" };
var cursor = { x: 0, y: 0 };
var circleBounds = getBounds(circleContainer);
var rippleBounds = getBounds(cardContainer);
var radius = circleBounds.w2;
var padding = -radius;
var duration = 0.5;
var requestId = null;
var standardCurve = new CustomEase("standardCurve", "0.4, 0.0, 0.2, 1");
TweenLite.defaultEase = standardCurve;
TweenLite.set([circle, ripple], { xPercent: -50, yPercent: -50 });
var tl = new TimelineMax({ reversed: true });
circle.addEventListener("click", toggleAnimation);
closeButton.addEventListener("click", toggleAnimation);
window.addEventListener("resize", requestUpdate);
TweenLite.set("main", { autoAlpha: 1 });
function toggleAnimation() {
update();
tl.reversed(!tl.reversed());
}
function update() {
console.log('update');
var progress = tl.progress() || 0;
var reversed = tl.reversed() || false;
tl.progress(0).clear();
circleBounds = getBounds(circleContainer);
rippleBounds = getBounds(cardContainer);
updateBezier();
var delay = getDelay();
var dt = duration - delay;
var dx = rippleBounds.w2;
var dy = rippleBounds.h2;
var tx = dx - radius - p3.x;
var ty = dy - radius - p3.y;
var size = Math.sqrt(dx * dx + dy * dy) * 2;
TweenLite.set(rippleContainer, { x: tx, y: ty });
var circleClone;
var clones = circleContainer.querySelectorAll('.circle.clone');
if(clones.length === 0) {
circleClone = circle.cloneNode(true);
circleClone.classList.add('clone');
circleClone.style.left = 0;
circleClone.style.top = 0;
circleContainer.insertBefore(circleClone, circleContainer.firstChild);
}
else
circleClone = clones[0];
tl.set(circle, { autoAlpha: 1 })
.set([card, circle], { autoAlpha: 0 })
.set(circleClone, { autoAlpha: 0 })
.set([ripple, circleClone], { autoAlpha: 1 })
.to([circleClone, ripple], duration, { bezier }, 0)
.to(circleIcon, duration, { autoAlpha: 0 }, 0)
.to(ripple, dt, { width: size, height: size, onComplete: () => {
tl.set(cardContainer, { borderWidth: 0, background: cardStyle.background, boxShadow: cardStyle.boxShadow })
.set([ripple, circleClone], { autoAlpha: 0, scale: 0 })
.set(card, { autoAlpha: 1 })
} }, delay)
.to(circleClone, dt, { autoAlpha: 0, scale: 0 }, delay)
.progress(progress)
.reversed(reversed);
requestId = null;
}
function updateBezier() {
p3.x = rippleBounds.cx - circleBounds.cx;
p3.y = rippleBounds.cy - circleBounds.cy;
var dx = p3.x - p0.x;
var dy = p3.y - p0.y;
if (p3.y > p0.y) {
p1.x = p0.x;
p1.y = p0.y + (dy * kappa);
p2.x = p3.x - (dx * kappa);
p2.y = p3.y;
} else {
p1.x = p0.x + (dx * kappa);
p1.y = p0.y;
p2.x = p3.x;
p2.y = p3.y - (dy * kappa);
}
}
function getDelay() {
cursor.x = p0.x;
cursor.y = p0.y;
var k = 0.0001;
var cx = circleBounds.cx;
var cy = circleBounds.cy;
var rx = rippleBounds.x + padding;
var ry = rippleBounds.x + padding;
var rw = rippleBounds.w - padding * 2;
var rh = rippleBounds.h - padding * 2;
var delay = 0;
var tween = TweenLite.to(cursor, duration, { bezier, paused: true });
for (var i = 0; i <= 1; i += k) {
tween.progress(i);
var x = cx + cursor.x;
var y = cy + cursor.y;
if (pointInRect(x, y, rx, ry, rw, rh)) {
delay = tween.time();
break;
}
}
return delay;
}
function getBounds(element) {
var rect = element.getBoundingClientRect();
var scrollTop = window.pageYOffset || root.scrollTop || body.scrollTop || 0;
var scrollLeft = window.pageXOffset || root.scrollLeft || body.scrollLeft || 0;
var clientTop = root.clientTop || body.clientTop || 0;
var clientLeft = root.clientLeft || body.clientLeft || 0;
var x = Math.round(rect.left + scrollLeft - clientLeft);
var y = Math.round(rect.top + scrollTop - clientTop);
var w = rect.width;
var h = rect.height;
var w2 = w / 2;
var h2 = h / 2;
var cx = x + w2;
var cy = y + h2;
return { x, y, w, h, w2, h2, cx, cy };
}
function requestUpdate() {
if (!requestId) {
requestId = requestAnimationFrame(update);
}
}
function pointInRect(px, py, rx, ry, rw, rh) {
return px >= rx && py >= ry && px <= rx + rw && py <= ry + rh;
}
Also see: Tab Triggers