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. 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.
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.
If the stylesheet 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 CSS 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.
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.
// ZIM is a JavaScript Canvas Framework for coding creativity!
// https://zimjs.com - please visit to start a wonderful coding journey.
// The main site has banner sections of TEN excellent uses of ZIM.
// ZIM provides many conveniences, components and controls
// to help designers, developers and artists create interactive media
// https://zimjs.com/about.html - why ZIM, features, applications
// https://zimjs.com/docs.html - expand open any feature for info and examples
// Here are CodePen examples with comments for learning:
// https://codepen.io/zimjs/pens/public - ZIM CodePen
// https://codepen.io/danzen/pens/public - ZIM Founder's CodePen
// https://codepen.io/zimjs/post/welcome-to-zim-on-codepen
// There are also many tutorials, videos and references here:
// https://zimjs.com/learn.html - ZIM Skool, ZIM Kids, ZIM Badges, etc.
// https://zimjs.com/code.html - ZIM Template, tools and more
// https://zimjs.com/slack/ - come join us on Slack for discussion and support
// -----------------
// ZIM is powered by CreateJS so we import CreateJS and ZIM in CodePen settings
// We make a Frame object which makes a stage on an HTML canvas
// We then add objects to the stage and update the stage to see them
const frame = new Frame("fit", 1024, 768, blue, darker); // see docs for other options
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
let stage = frame.stage;
let stageW = frame.width;
let stageH = frame.height;
// CODE HERE
// Create a page border of ringed colors
// we add to a ZIM Container so we can animate these later with a sequence
const rings = new Container(stageW, stageH).addTo(); // adds to stage by default
// A ZIM series will return each item in order every time it is used
// so when colors gets called it will give orange then blue repeatedly
// We use this when making the rings in the loop below
// orange and blue are ZIM colors - or use any HTML colors in "quotes"
const colors = series(orange, blue);
// Use a ZIM loop which is like an easy for(){} loop
// ZIM loop also loops through arrays, object and containers
// Here we loop 12 times and each loop calls an arrow function
// which is given the loop number i (the iterator)
loop(12, i=>{
// start with a 640 pixel radius and get smaller each loop
// this way smaller circles sit on top and we can see them
new Circle(640-i*20, colors).center(rings);
});
// Often we animate from the current value TO the value specified in animate()
// Here we animate FROM a scale of 0 to the current scale of 1
rings.animate({
from:true, // end the animation at the current values for properties (eg. scale:1)
props:{scale:0}, // animate from scale of 0
time:700, // time in milliseconds for each animation
sequence:100, // wait this long before animating the next object in container
});
// We could add a call:()=>{} in animate() to start app after we animate
// but want app to start a little before the animation is done
// so use a ZIM timeout(time, callback)
// This is like JS setTimeout but parameters are reversed
// ZIM interval(time, callback) is similar
// Both these functions have more features than the JS versions
timeout(1500, ()=>{
// the ZIM particle emitter
// we can also have startPaused:true and store in const emitter
// and then use emitter.spurt() any time you want
new Emitter({
obj:new Circle(80, dark),
num:5, // makes five at a time rather than one at a time
gravity:0 // default is 10 to fall down like fireworks
}).center();
// ZIM has two ways to handle parameters (ZIM DUO)
// 1. normal where the order matches the docs
// text, size, font, color, etc.
// Here we use the default size:
// new Label("CREATE", null, "impact", blue)
// 2. or a single configuration object
// where the properties match the parameter names
// then order does not matter and we do not need nulls:
new Label({text:"CREATE!", font:"impact", color:blue})
.sca(1.5) // chaining fun!
.centerReg() // so scale and rotation happens around center
.animate({
props:{color:orange, scale:3}, // properties to animate
time:1700, // time in ms
rewind:true,
rewindWait:2000, // wait before rewinding
loop:true,
loopWait:2000, // wait before looping
ease:"backInOut"
})
.wiggle("rotation", 0, 2, 5, 1000, 1500);
// property, startValue, min, max, minTime, maxTime
}); // end of timeout
// ZIM animate() will update stage but without animation would need below:
// stage.update(); // this is needed to show any changes
timeout(2500, ()=>{
// FOOTER
// call remote script to make ZIM Foundation for Creative Coding icon and a greet link
createIcon();
createGreet();
});
// 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=Label
// https://zimjs.com/docs.html?item=animate
// https://zimjs.com/docs.html?item=wiggle
// https://zimjs.com/docs.html?item=loop
// https://zimjs.com/docs.html?item=sca
// https://zimjs.com/docs.html?item=addTo
// https://zimjs.com/docs.html?item=centerReg
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=Emitter
// https://zimjs.com/docs.html?item=timeout
// https://zimjs.com/docs.html?item=interval
// https://zimjs.com/docs.html?item=series
// https://zimjs.com/docs.html?item=zog
}); // end of ready
Also see: Tab Triggers