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 assets = ["bird01.png", "bird02.png", "pelican.png", "pigeon.png", "tucan.png"];
const path = "https://assets.codepen.io/2104200/";
const scaling = FIT; // try FILL
const width = 1024;
const height = 768;
const color = purple;
const outerColor = purple.darken(.5);
const frame = new Frame(scaling, width, height, color, outerColor, assets, path);
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 ;-)
// images thanks to https://vecteezy.com - chopped up by Nived!
// CODE HERE
const cols = 9;
const rows = 5;
const startScale = .35;
const birds = [];
// make clones of enough birds to make cols*rows
// we will just reuse the same bird images over and over
loop (cols*rows, ()=>{
// asset() receives a string name of the asset
// but it also accepts ZIM VEE dynamic parameters to pick from.
// In this case it picks randomly from the assets array.
// Clone assets if you want more than one.
birds.push(asset(assets).clone());
});
// we will makeBirds over and over again as the mousemoves
let tile;
function makeBirds() {
if (tile) {
// get rid of last tile
// we could just dispose() - but it is more efficient to reuse the birds
// so remove them from the tile before disposing
tile.removeAllChildren();
tile.dispose();
}
// Make sure the birds are center registration
// so when we scale them, they stays in place better in the Tile
// (otherwise each would scale from its top left corner).
// We randomly adjust the scale and reg later so this resets it
loop(birds, bird=>{
bird.sca(startScale).centerReg();
});
// randomize the series the tile will pick from ZIM VEE again...
let birdSeries = series(shuffle(birds));
// make the tile and DO NOT let it clone
// this is important - we want to reuse the birds we have
// if we disposed without removing the birds first
// then we would want to leave clone true - which is the default
tile = new Tile({
obj:birdSeries,
cols:cols,
rows:rows,
spacingH:rand(-150,-120),
spacingV:rand(-150,-120),
clone:false
}).ble("difference");
// randomize the scale and registration point
tile.loop(bird=>{
// true is min range too -.3 to -.7 as well
// this makes it flip sometimes
let s = rand(.3,.7,null,true);
// we want to keep the y scale positive
// and just adjust the regY a little so not so vertically aligned
bird.sca(s, Math.abs(s)).reg(null,bird.regY+rand(-50,50));
});
tile.center();
stage.update();
}
makeBirds();
stage.on("stagemousemove", makeBirds);
// Love ZIM - this was so pleasant to make
// DOCS FOR ITEMS USED
// https://zimjs.com/docs.html?item=Frame
// https://zimjs.com/docs.html?item=loop
// https://zimjs.com/docs.html?item=ble
// https://zimjs.com/docs.html?item=reg
// https://zimjs.com/docs.html?item=sca
// https://zimjs.com/docs.html?item=centerReg
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=Tile
// https://zimjs.com/docs.html?item=rand
// 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();
createGreet();
}); // end of ready
Also see: Tab Triggers