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 URLs 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 its URL and the proper URL extension.
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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
<h1>iOS 9 App Switcher</h1>
<div class="app-container" id="multitask-view"></div>
<div id="credits">
<p>Developed by <a href="http://migueljimenez.co" target="_blank">Miguel Jiménez</a> | <a target="_blank" href="https://twitter.com/jachinte">@jachinte</a></p>
<p>
This demo is inspired on this blog <a href="https://iamralpht.github.io/constraints/" target="_blank">post</a>.
<br /><a href="https://github.com/iamralpht/slalom" target="_blank">Slalon</a> is a JavaScript library developed by Ralph Thomas
<br />
Icons from <a href="https://www.iconfinder.com/iconsets/web-social-and-folder-icons" target="_blank">Iconfinder</a>, and screenshots from <a href="http://pttrns.com/" target="_blank">Pttrns</a>
</p>
</div>
* {
box-sizing: border-box;
}
body, html {
height: 100%;
}
body {
background: black;
background-image: linear-gradient(rgba(85, 239, 203, 0.2), rgba(91, 202, 255, 0.2));
font-family: "Arial";
margin: 0;
padding: 30px 0 0 0;
}
h1 {
color: white;
font-weight: normal;
text-align: center;
}
#credits {
margin: auto;
text-align: center;
width: 350px;
}
#credits p {
color: #777;
font-size: 13px;
margin: 15px 0 0 0;
padding: 0;
}
#credits p a {
color: #fff;
text-decoration: none;
}
#credits p a:first-child {
color: #BADA55;
}
.app-container {
background: black;
background-image: linear-gradient(rgba(85, 239, 203, 0.5), rgba(91, 202, 255, 0.5));
cursor: ew-resize;
height: 667px;
margin: auto;
overflow: hidden;
position: relative;
width: 375px;
}
.app {
left: 0;
pointer-events: none;
position: absolute;
text-align: left;
top: 0;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
will-change: transform;
}
.app span {
color: white;
display: block;
letter-spacing: 0.5px;
line-height: 24px;
padding: 0 0 10px 0;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
}
.app span img {
height: 24px;
margin-right: 5px;
vertical-align: middle;
width: 24px;
}
.app > img {
border-radius: 6px;
box-shadow: 0 3px 7px 0 rgba(0, 0, 0, 0.4);
height: 100%;
width: 100%;
}
"use strict";
// Helpers to make cassowary.js a bit clearer.
var weak = c.Strength.weak;
var medium = c.Strength.medium;
var strong = c.Strength.strong;
var required = c.Strength.required;
var eq = function(a1, a2, strength, w) {
return new c.Equation(a1, a2, strength || weak, w||0);
};
var neq = function(a1, a2, a3) { return new c.Inequality(a1, a2, a3); };
var geq = function(a1, a2, str, w) { return new c.Inequality(a1, c.GEQ, a2, str, w); };
var leq = function(a1, a2, str, w) { return new c.Inequality(a1, c.LEQ, a2, str, w); };
var stay = function(v, strength, weight) {
return new c.StayConstraint(v, strength||weak, weight||0);
};
var weakStay = function(v, w) { return stay(v, weak, w||0); };
var mediumStay = function(v, w) { return stay(v, medium, w||0); };
var strongStay = function(v, w) { return stay(v, strong, w||0); };
var requiredStay = function(v, w) { return stay(v, required, w||0); };
function multiTaskView(appContainer, data) {
"use strict";
var context = new MotionContext(),
solver = context.solver(),
scale = 0.42,
lastApp = null,
apps = [],
APP_WIDTH = 750 * scale,
APP_HEIGHT = 1336 * scale,
GROWTH_FACTOR = 0.02,
X_MARGIN = 60,
Y_MARGIN = 50,
// (left) space between apps
LEFT_GAP = 5,
// (right) space after apps are moved
RIGHT_GAP = APP_WIDTH * -0.2;
for (var i = 0; i < data.length; i++) {
var node = document.createElement("div"),
app = new Box(node),
growthFactor = i * GROWTH_FACTOR,
h = APP_HEIGHT * (growthFactor / 2),
w = APP_WIDTH * growthFactor,
// Create the HTML structure
screen = document.createElement("img"),
title = document.createElement("span"),
icon = document.createElement("img");
screen.src = data[i].image;
icon.src = data[i].icon;
title.appendChild(icon);
title.appendChild(document.createTextNode(data[i].name));
node.className = "app";
node.appendChild(title);
node.appendChild(screen);
// Create the constraints
app.x = new c.Variable({ name: "app-" + i + "-x" });
app.right = new c.Variable({ name: "app-" + i + "-right" });
app.edge = new c.Variable({ name: "app-" + i + "-right-edge" });
app.y = Y_MARGIN - h;
app.bottom = APP_HEIGHT + h;
// App's width
solver.add(eq(app.right, c.plus(app.x, APP_WIDTH + w), medium));
// App's right gap
solver.add(eq(app.edge, c.plus(app.right, RIGHT_GAP), medium));
// Pin the first app to 0, and add a motion constraint
if (i === 0) {
solver.add(eq(app.x, 0, weak, 100));
context.addMotionConstraint(new MotionConstraint(app.x, ">=", 0));
context.addMotionConstraint(new MotionConstraint(app.x, "<=", X_MARGIN));
} else {
// The app mustn't reveal any space between it and the previous app.
solver.add(leq(app.x, apps[i-1].edge, medium, 0));
// Make the app tend toward the left (zero). Use a lower priority than
// the first app so the solver will prefer for the first app to be
// zero than any of the additional apps.
solver.add(eq(app.x, 0, weak, 0));
// The app must be to the right of the previous app's left edge, plus the left gap
solver.add(geq(app.x, c.plus(apps[i-1].x, LEFT_GAP), medium, 0));
// We constrain on the gap between this app and the one that came before
// it. So first, create a variable that will be the gap to constrain on.
var gap = new c.Variable();
// gap = apps[i].x - apps[i-1].x
solver.add(eq(gap, c.minus(app.x, apps[i-1].x)));
// Use the OR operator for the motion constraint. Eiher the gap is LEFT_GAP
// or it should be APP_WIDTH.
// This constraint is captive (it will be enforced even if we'd go through it)
// This constraint isn't active when dragging (overdragCoefficient: 0)
// context.addMotionConstraint(new MotionConstraint(gap, '||', [LEFT_GAP, APP_WIDTH], {
// overdragCoefficient: 0,
// captive: true
// }));
}
apps.push(app);
context.addBox(app);
appContainer.appendChild(app.element());
lastApp = app;
}
// Modify CSS properties to maintain a clear view of the apps
for (var i = 0; i < apps.length - 1; i++) {
attachObserver(apps[i], apps[i + 1]);
};
// Make a manipulator. It takes touch events and updates a constrained variable
// from them.
var handler = new Manipulator(lastApp.x, appContainer, "x");
context.addManipulator(handler);
}
function attachObserver (current, next) {
"use strict";
var offset = 40,
$current = current.element(),
$next = next.element(),
observer = new MutationObserver(function(mutations) {
var mutation = mutations[mutations.length - 1];
if (mutation.attributeName === "style") {
// e.g., translate3d(4px, 64px, 0px)
var transform = mutation.target.style.transform,
values = transform
.replace(/translate3d\(|\s|\)/g, "")
.split(","),
distance = next.x.value - current.x.value,
factor = (distance / offset);
factor = factor > 1 ? 1 : factor;
var opacity = factor,
blur = "blur(" + ((1 - factor) * 15) + "px)";
$current.style["-webkit-filter"] = blur;
$current.style["-moz-filter"] = blur;
$current.style["-o-filter"] = blur;
$current.style.filter = blur;
// $current.style.opacity = opacity;
}
});
observer.observe($next, {
attributes: true,
childList: false,
characterData: false
});
}
var base = "https://jachinte.github.io/examples/ios9-multitask/",
data = [
{image: base + "images/1.jpg", name: "Cool Name", icon: base + "images/icons/1.png"},
{image: base + "images/2.jpg", name: "Rock & Roll", icon: base + "images/icons/2.png"},
{image: base + "images/3.jpg", name: "Best App", icon: base + "images/icons/3.png"},
{image: base + "images/4.jpg", name: "Cool Name", icon: base + "images/icons/4.png"},
{image: base + "images/5.jpg", name: "Rock & Roll", icon: base + "images/icons/5.png"},
{image: base + "images/6.jpg", name: "Best App", icon: base + "images/icons/6.png"},
{image: base + "images/7.jpg", name: "Cool Name", icon: base + "images/icons/7.png"}
];
window.addEventListener('load', function () {
multiTaskView(document.getElementById("multitask-view"), data);
});
Also see: Tab Triggers