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.
<canvas></canvas>
<h1>404</h1>
<section>
<span>I'm lost... Take me home!</span>
</section>
body {
width: 100%;
height: 100vh;
overflow: hidden;
display: grid;
place-content: center;
background: #fff;
}
canvas {
position: absolute;
top: 0;
left: 0;
// z-index: 1;
}
h1 {
font-size: 500px;
color: #fff;
position: relative;
pointer-events: none;
margin: 80px 0 0;
padding: 0;
// z-index: 2;
}
section {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: grid;
place-content: center;
pointer-events: none;
}
span {
display: inline-block;
padding: 20px 60px;
font-family: serif;
background: #e1e444;
color: #000;
pointer-events: all;
cursor: pointer;
border-radius: 55px;
font-size: 24px;
letter-spacing: 1px;
transition: color 0.2s, background 0.2s;
&:hover {
background: #000;
color: #fff;
}
// transform: translate(-50% -50%);
}
const canvas = document.querySelector("canvas");
const canvasImages = [];
canvas.width = innerWidth;
canvas.height = innerHeight;
const ctx = canvas.getContext("2d");
const feather1 =
"M527.4 85.1v-2.3c0-1.6-.2-3.1-.5-4.7a294 294 0 0 1-4.7-36.3c-.3-4.7-1-9.4-1.6-14-.2-1.9-.8-3.6-1.2-5.4-.2-.7-.4-1.4-.4-2.1 0-1 .4-1.9 1.3-2.2 1-.3 2.1-.4 2.7.7.7 1.2 2 1.5 3.2 1.5h5.4c2.6-.2 4.3.9 5.2 3.2l3.4 9c.4 1.1 1 2 1.8 3.4 1.2-2.4.4-4.4.2-6.3-.1-2-.5-3.9-.8-6.3 5.3 4.5 9.5 9 9.6 16v13.3c-.3 6.9-.5 13.7.3 20.6.5 4.5 1.2 9 3 13.3 1.2 3.2 3 6.2 5.7 8.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8-10.1 9.4-20.2 14.1-30.4 4.2-9 8.7-17.8 14.6-25.8 3.6-4.8 7.5-9.5 11.2-14.2l3.7-4.9c-1.3-.4-2 .3-2.7.8a67 67 0 0 0-14.5 12.3 102.2 102.2 0 0 0-18 29.4c-3 7.5-5.8 15.1-9.6 22.3a95 95 0 0 1-14.7 21.6c-1.9 2-4 3.6-6.1 5-2.7 1.9-5.7 1.6-8.6.5a5 5 0 0 1-3.3-5.7c.2-1.1.5-2.3 1-3.3a95.6 95.6 0 0 0 7.6-21.1c1.8-6.3 3.3-12.7 5-19a98.6 98.6 0 0 1 15.3-31.2l14.3-18.7c.6-.7 1-1.6 1.4-2.5-2.9.9-5.1 2.6-7.3 4.6a72.5 72.5 0 0 0-12.9 16.8 241.5 241.5 0 0 0-17 36c-4 10.5-8.2 20.8-13.6 30.6a47 47 0 0 1-8.8 11.3c.2-.5.3-1.1.6-1.6a331.5 331.5 0 0 0 19.1-44.6A155 155 0 0 1 434 121c3.6-5.5 7.7-10.8 11.5-16.1l1-1.6a95 95 0 0 0-16.7 18.5c-8 12.2-13.8 25.5-19 39a1205 1205 0 0 1-11.3 28 29.7 29.7 0 0 1-7.8 10.5c-1.2 1.1-2.5 2.3-4.6 2.3l-.3-4.1c-3.6-.1-6.4 2.4-10 3.4l5-14.3c-3 2.7-4.5 6.5-7.9 9.2l-2-3c-.9.8-1.7 1.4-2.3 2.2-1.4 1.7-2.5 3.5-3.9 5.2-2.3 3-3.8 3.4-7.3 2.3a21 21 0 0 1-3.7-1.5c-1.7-1-2.3-1.9-1.7-3.7a35 35 0 0 0-1-20 160 160 0 0 1-4.9-41.2c0-3.6 0-7.1 2-10.3v-.6c-1.2-.2-1.6.7-2 1.4-1.6 2.7-3.1 5.5-4.5 8.3-2.7 5.6-5.1 11.4-8 17a72 72 0 0 1-40.7 35c-1.8.8-3.6 1.4-5.7 1.2-1-.2-2 .6-2.9 1.2l-6.5 5.7c-1.1 1-2.4 1.8-3.7 2.4-1.7.8-2.8 0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-14.1-8.9-19.9-.7-.8-1.5-2-.8-3.1.8-1.3 2.2-1 3.3-.6 2.6.7 4.7 2 6.4 4 3 3.7 5 8 6.6 12.5 2.8 7.8 4.1 16 4.7 24.2.6 8.5 1.6 17 3.7 25.2.6 2.6 1.5 5 2.4 7.6.3.9 1 1.6 1.5 2.4l.8-.2Z";
const images = [
"https://images.ctfassets.net/beeay9aupl8z/3kS8zCAqAaViBuakHdni1D/0aecd7a6a83e4732f3e2275c29bbedf5/bird3.jpg?w=736&h=736&fm=jpg&fl=progressive&q=80",
"https://images.ctfassets.net/beeay9aupl8z/SrzRQTz94ucUUXSRQw57n/d389f72fa0695d30b3b8c9f22278c7e0/beach.jpg?w=736&h=736&fm=jpg&fl=progressive&q=80",
"https://images.ctfassets.net/beeay9aupl8z/73bT2TBQiUOtaQYdJLQgMt/50c131ed50ad2a9e56c3bc7044bf97a1/boarder.jpg?w=736&h=736&fm=jpg&fl=progressive&q=80",
"https://images.ctfassets.net/beeay9aupl8z/7xXaESXat6mBfjFQAzamrv/2f43ef3ed50c3085ab393b1b8f29f1cc/bird2.jpg?w=736&h=736&fm=jpg&fl=progressive&q=80",
"https://images.ctfassets.net/beeay9aupl8z/36xnMMfdPZiymYMnYJMjNf/4d682fdd5ed8ca5ed89361b1d195799b/bird1.jpg?w=736&h=736&fm=jpg&fl=progressive&q=80",
"https://images.ctfassets.net/beeay9aupl8z/7t142CYF9wLFONxLLWmDdV/b14dd5c3afb71ea13a5489589510c13e/bird4.jpg?w=736&h=736&fm=jpg&fl=progressive&q=80",
"https://images.ctfassets.net/beeay9aupl8z/1W4sU23GGrTlBYIBctEH0j/bf37019afc031222a1117aa19945c325/BirdLoop.jpg?w=736&h=736&fm=jpg&fl=progressive&q=80",
"https://images.ctfassets.net/beeay9aupl8z/44rtppWgqZs9SOYgW3JCdx/e0707dd82de704b073da5883047da9db/birddock.jpg?w=736&h=736&fm=jpg&fl=progressive&q=80"
];
let p = new Path2D(feather1);
images.forEach((image) => {
const canvasImage = new Image();
canvasImage.src = image;
canvasImages.push(canvasImage);
});
let prevX = 0;
let prevY = 0;
let prevRotation = 0;
const setDraw = (e) => {
draw(e.clientX, e.clientY);
prevX = e.clientX;
prevY = e.clientY;
};
const placeImage = (ctx, f, rotation, scale) => {
ctx.save(); // Save the context before clipping
ctx.clip(f); // Clip to whatever path is on the context
ctx.rotate(-rotation);
ctx.drawImage(
gsap.utils.random(canvasImages),
(-736 / 2) * scale,
(-736 / 2) * scale,
736 * scale,
736 * scale
);
ctx.restore(); // Get rid of the clipping region
};
let black = false;
const draw = (x, y) => {
let f = new Path2D();
const scale = gsap.utils.random(0.1, 0.7, 0.1);
const rotation = gsap.utils.random(0, 6.2832);
const matrix = {
a: scale,
b: 0,
c: 0,
d: scale,
e: (scale * -736) / 2,
f: (scale * -218) / 2
};
f.addPath(p, matrix);
ctx.rotate(-prevRotation);
ctx.translate(x - prevX, y - prevY);
// var pat = ctx.createPattern(image, "repeat");
ctx.rotate(rotation);
if (black) {
ctx.fill(f);
black = false;
} else {
placeImage(ctx, f, rotation, scale);
black = true;
}
prevRotation = rotation;
ctx.restore();
};
// var throttleFn = _.throttle(, 100);
// canvas.addEventListener("click", setDraw, false);
canvas.addEventListener("mousemove", _.throttle(setDraw, 100), false);
Also see: Tab Triggers