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.
const frame = new Frame("fit", 1024, 768, light, darker);
frame.on("ready", ()=>{ // ES6 Arrow Function - similar to function(){}
zog("ready from ZIM Frame"); // logs in console (F12 - choose console)
// often need below - so consider it part of the template
const stage = frame.stage;
const stageW = frame.width;
const stageH = frame.height;
// REFERENCES for ZIM at https://zimjs.com
// see https://zimjs.com/intro.html for an intro example
// see https://zimjs.com/learn.html for video and code tutorials
// see https://zimjs.com/docs.html for documentation
// see https://codepen.io/topic/zim/ for ZIM on CodePen
// *** NOTE: ZIM Cat defaults to time in seconds
// All previous versions, examples, videos, etc. have time in milliseconds
// This can be set back with TIME = "milliseconds" but we suggest you give it a try!
// There will be a warning in the conslole if your animation is not moving ;-)
// CODE HERE
// we will save to png everything in the ornament container
const ornament = new Container(600, 600).center().mov(0,-40);
// make it so the ball will change colors when clicked on
const colors = series(yellow, yellow.darken(.5),moon,green,green.darken(.5),red,red.darken(.5),pink,purple,brown, brown.darken(.5),black,blue.darken(.5),blue);
const ball = new Circle(200, blue).center(ornament).mov(0,50).tap(()=>{
ball.color = colors();
stage.update();
});
// a container to hold all our draggable stripes
const stripes = new Container(stageW, stageH).center(ornament);
// an array of the stripes
const patterns = [
new Rectangle(stageW+10, 20, red),
new Rectangle(stageW+10, 30, green),
new Rectangle(stageW+10, 10, yellow),
new Rectangle(stageW+10, 50, dark),
new Rectangle(stageW+10, 70, dark),
new Rectangle(stageW+10, 40, white),
// type, colors, size, cols, rows, spacingH, spacingV, interval, startPaused, backgroundColor, gradient, cache
pizzazz.makePattern("slants", series(green,red), 30, 100, 1, 0, 0, null, null, red).reg(0,0),
pizzazz.makePattern("bling", silver, 60, 100, 1, 10).reg(0,0),
pizzazz.makePattern("noise", series(purple,pink), 20, 200, 1, 0, 0).reg(0,0),
pizzazz.makePattern("slants", series(green,red), 30, 100, 1, 0, 0, null, null, red).sca(-1,1).reg(0,0),
pizzazz.makePattern("dots", series(green,red), 20, 100, 1, 5, 0, null, null, red).reg(0,0),
new Squiggle({
color:lighter,
thickness:10,
points:40,
length:stageW+10,
interactive:false
}).expand(0),
new Squiggle({
color:red,
thickness:8,
points:30,
length:(stageW+10)/2,
interactive:false
}).sca(2,1).expand(0)
];
// loop through, randomly place and drag the stripes
loop(patterns, stripe=>{
loop(2, i=>{ // make two of each
stripe
.clone()
.pos(0, rand(stageH-stripe.height), CENTER, TOP, stripes)
.drag(new Boundary(-10,0,0,stageH-stripe.height));
if (stripe.type != "Squiggle") stripe.cache();
})
})
// The ring will offset the ornament
const ring = new Circle(270, clear, darker, 140).loc(ball, null, ornament)
const gradient = new Circle(200, new RadialColor([grey, white],[1,.3], 0,0,0, 50,-50,200))
.alp(.2)
.loc(ball, null, ornament);
const hoop = new Circle(40, clear, silver, 2).pos(0,-230, CENTER, CENTER, ornament).noMouse();
const top = new Rectangle(80,70,new GradientColor([grey,silver,grey],[0,.65,1],0,0,80,0))
.pos(0,-180, CENTER, CENTER, ornament).noMouse();
// prepare the save steps
const loader = new Loader();
const madeWith = frame.madeWith();
madeWith.icon.alp(1); // usually this a little rollover thing so its start alpha is down
new Button({
label:"SAVE",
backgroundColor:red.darken(.3),
rollBackgroundColor:green.darken(.3),
corner:10
}).sca(.7).pos(0,280,CENTER,CENTER).tap(()=>{
// remove the things we do not want and add a logo
ring.visible = false;
stripes.setMask(ball);
madeWith.pos(20,20,RIGHT,BOTTOM,ornament);
// save with the Loader
loader.save(ornament, "ornament"); // could save as a jpg too
// add the things back
madeWith.removeFrom();
stripes.setMask(null);
ring.visible = true;
});
stage.update(); // this is needed to show any changes
// DOCS FOR ITEMS USED
// https://zimjs.com/docs.html?item=Frame
// https://zimjs.com/docs.html?item=Container
// https://zimjs.com/docs.html?item=Circle
// https://zimjs.com/docs.html?item=Rectangle
// https://zimjs.com/docs.html?item=Squiggle
// https://zimjs.com/docs.html?item=Button
// https://zimjs.com/docs.html?item=Loader
// https://zimjs.com/docs.html?item=tap
// https://zimjs.com/docs.html?item=drag
// https://zimjs.com/docs.html?item=noMouse
// https://zimjs.com/docs.html?item=loop
// https://zimjs.com/docs.html?item=pos
// https://zimjs.com/docs.html?item=loc
// https://zimjs.com/docs.html?item=mov
// https://zimjs.com/docs.html?item=alp
// https://zimjs.com/docs.html?item=reg
// https://zimjs.com/docs.html?item=sca
// https://zimjs.com/docs.html?item=removeFrom
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=expand
// https://zimjs.com/docs.html?item=setMask
// https://zimjs.com/docs.html?item=rand
// https://zimjs.com/docs.html?item=Boundary
// https://zimjs.com/docs.html?item=GradientColor
// https://zimjs.com/docs.html?item=RadialColor
// https://zimjs.com/docs.html?item=series
// https://zimjs.com/docs.html?item=darken
// https://zimjs.com/docs.html?item=zog
// FOOTER
// call remote script to make ZIM icon - you will not need this
createIcon();
}); // end of ready
Also see: Tab Triggers