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 = ["twelve.jpg", {font:"Reuben", src:"Reuben.otf"}];
const path = "https://assets.codepen.io/2104200/";
const frame = new Frame("fit", 1024, 768, red.darken(.2), dark, 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
// CODE HERE
// The basic code to do this is about 10 lines and took 20 minutes to make
// Here we demonstrate the many options that ZIM has to really get what you want
// Images are from the Internet and on several sites but none telling who made them - sorry!
// We could use Label("Twelve Days of Christmas Count Down!")
// but Label does not provide letterSpacing
// so we are using LabelLetters which breaks a Label up into individual Labels
// These can be controlled with basic html tags as well - we do not do that here
// but we do randomly rotate the letters a little and animate them
// Sound would be nice - and is very easy - but we did not bother
const title = new LabelLetters({
label:new Label({
text:"Twelve Days of Christmas Count Down!",
font:"Reuben",
color:white
}),
letterSpacing:4
}).pos(0,50,CENTER).noMouse();
loop(title.labels, label=>{
// the true means include a negative range as well
// we could just use rand(-6,6) but then some letters would not be rotated much
// so we wanted at least 3 rotation either negative or positive
// We built this option into ZIM rand() because we know we want it at times
label.rot(rand(3,6,null,true)).animate({
wait:.5,
props:{rotation:-label.rotation, scale:1.5},
time:rand(.2,.4),
rewind:true
});
});
// the picture is all one picture
// we could have broken this up in Photoshop but we can also chop pictures in ZIM
const thumbs = chop(asset("twelve.jpg"), 4, 3, false); // false to get array not Tile
// we are going to add a white border of 20 to the picture
const size = thumbs[0].width + 20;
// build ZIM Flipper objects to allow the cards to flip
const cards = [];
loop(thumbs, (thumb,i)=>{
let front = new Rectangle(size, size, green.darken(.2))
new Label({text:i+1, font:"Reuben", size:50, color:green.darken(.7)}).center(front);
let back = new Rectangle(size, size, lighter);
thumb.center(back);
cards.push(new Flipper(front, back).noMouse()); // turn off the cards
});
// Tile the cards - the true is for unique which will use the array
// otherwise the array would be a ZIM VEE value and the Tile would pick randomly from the array and clone
const tile = new Tile(cards, 4, 3, 40, 40, true).pos(-50,30,CENTER,CENTER);
// create an Indicator for the countdown
// this normally goes horizontally so we will rotate it
const indicator = new Indicator({
width:400,
height:70,
num:5,
foregroundColor:dark,
backgroundColor:lighter,
backdropColor:clear,
indicatorType:"square",
fill:true,
selectedIndex:4
}).rot(90).pos(70,0,RIGHT,CENTER);
// Make a function to activate a card
function turnOn(num) {
// get the card from the tile and turn on its interactivity
let card = tile.items[num].mouse();
// when we start to flip turn off its interactivity otherwise we could flip back
card.on("flip", ()=>{card.noMouse();});
// when it is done flipping emit snowflakes and start the countdown
card.on("flipped", ()=>{
// wait to let user concentrate on the card
// then start countdown
timeout(.5, ()=>{
countEmitter.spurt(20);
indicator.selectedIndex = -1;
interval(1, obj=>{
indicator.selectedIndex = obj.count-1;
if (obj.count == obj.total) {
// when the countdown is done activate the next card
turnOn(card.tileNum+1);
}
}, indicator.num); // make the interval run this number of times
}); // end timeout
}); // end flipped function
} // end turnOn function
// turn on the first card
turnOn(0);
// create an emitter for the snowflakes
// we will emit the results of the makeFlake function (below)
const countEmitter = new Emitter({
obj:makeFlake, // new Poly({min:30, max:50}, [5,9],.6,white), // would be stars
animation:{
props:{
regX:{min:100, max:300}, // make it wobble
rotation:[{min:600, max:1200}, {min:-600, max:-1200}] // min and max, negative or positive rotation
},
time:7, // match the life of the flake
loop:true
},
startPaused:true, // pause the emitter to start - we spurt() in the countdown above
force:{min:1, max:6}, // shoot the flakes out at various forces to spread them out
gravity:2, // make the gravity less for light snow!
fade:false,
life:7,
angle:{min:180, max:300}, // 0 is to the right along the x axis - this shoots to the left
}).loc(indicator.lights[0]);
function makeFlake() {
let flake = new Container();
let w = rand(20,30);
let h = rand(70,110);
loop(3,i=>{new Rectangle(w,h,white).centerReg(flake).rot(i*120);});
return flake.noMouse().sca(.6);
}
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=Rectangle
// https://zimjs.com/docs.html?item=Poly
// https://zimjs.com/docs.html?item=Label
// https://zimjs.com/docs.html?item=LabelLetters
// https://zimjs.com/docs.html?item=Indicator
// https://zimjs.com/docs.html?item=mouse
// https://zimjs.com/docs.html?item=noMouse
// https://zimjs.com/docs.html?item=animate
// 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=bot
// https://zimjs.com/docs.html?item=rot
// 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=Flipper
// https://zimjs.com/docs.html?item=Emitter
// https://zimjs.com/docs.html?item=chop
// https://zimjs.com/docs.html?item=rand
// https://zimjs.com/docs.html?item=timeout
// https://zimjs.com/docs.html?item=interval
// 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().sca(.7).mov(-60,-90).bot();
}); // end of ready
Also see: Tab Triggers