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, "#A496A4".lighten(.8), "#A496A4".lighten(.3));
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
// The AHA Game
// Try and find the square that is not changing
const colors = ["#A5A7BB", "#A496A4", "#554d73"];
const size = 520; // size of game tile
let num = 4; // number of tiles per col or row
// Just some design - a backing focus rectangle
new Rectangle(900,530,"#A5A7BB",yellow).alp(.2).loc(50,70)
// Backing rectangle for game tile
new Rectangle(size+5,size+5,dark).rot(45).center();
// When we get the right square we emit particles
// These will be the same size as the tile
// but the tile sizes can be changed
// So... we could make a new emitter each time
// or there is a better solution below:
// ZIM has dynamic parameters - called ZIM VEE values or Pick Objects
// This means, we can pass in a ZIM VEE value to the obj parameter
// Each time the particle is made inside it will pick from the ZIM VEE value
// Different ZIM VEE values are as follows:
// [1,3,2] - random
// {min:10, max:20} - range
// series(1,2,3) - order,
// function(){return result;} - function
// We want to make a particle the size of the current tile
// so we can use a function to make the particle
// and then pass the function to the Emitter
// Note that the Rectangle being made also uses a ZIM VEE value
// It is using the colors array to pick randomly from the color
// This would not work without ZIM VEE system
function makeParticle() {
return new Rectangle(size/num,size/num, colors, dark).rot(45);
}
const emitter = new Emitter({
obj:makeParticle,
startPaused:true,
gravity:0,
force:{min:10, max:20}
});
// One square will always stay the same color
// This is the function to start each round
// and set the correct square and its color
let correct = null;
function startRound() {
correct = rand(num*num-1); // 0-value
correctColor = shuffle(colors)[0];
emitter.clearPool(); // emitter pools particles - which could be the wrong size
}
startRound();
// Create the tile in an interval
// We can pause and change the speed of a ZIM interval
// We will get rid of the old tile if there is one
// and make a new tile each time
// Passing in the colors array will make the tile pick randomly from the colors
// each time it makes a time - this is ZIM VEE again
let tile = null;
timer = interval(.6, ()=>{
if (tile) tile.removeFrom();
tile = new Tile(new Rectangle(size/num,size/num,colors,dark).centerReg(), num, num)
.rot(45)
.cur()
.centerReg(stage, 2) // above backing rectangles
tile.on("mousedown", ()=>{
wrong.score++;
});
let correctTile = tile.getChildAt(correct);
// correctTile.borderColor = red;
correctTile.color = correctColor;
correctTile.on("mousedown", ()=>{
emitter.loc(correctTile).spurt(10);
// go to next level
num++;
if (num > dial.max) num = dial.min;
dial.currentValue = num;
right.score++;
wrong.score--; // wrong value will also go up so fix that
startRound();
}, null, true); // only click once on correct tile
stage.update();
}, null, true); // start interval right away
// INTERFACE
STYLE = {
backgroundColor:"#554d73".lighten(.3),
toggleBackgroundColor:"#A5A7BB",
color:"#554d73",
shadowColor:"none",
font:"impact",
size:30,
shiftVertical:2 // for Impact font adjust on Toggle
}
// We decided after making the interface to animate it
// We spent a couple minutes adding it to a Container
// so we can animate them all with one animate call
// We make the container the same size as the stage
// and that will mean we do not have to reposition the interfaces
// as we had already made and positioned relative to the stage
// Note, again, because we had already placed the objects,
// it is easier to animate from some other property to its final property
// This also has the advantage of being able to "bypass"
// all the animations with the ANIMATE constant set to false
// Uncomment this line to see - this is good for saving time while developing
// ANIMATE = false;
const interface = new Container(stageW, stageH)
.addTo()
.animate({
from:true,
wait:1,
props:{y:300},
ease:"backOut",
time:.7
})
const dial = new Dial({min:4, max:12})
.pos(70,30,LEFT,BOTTOM,interface)
.change(e=>{
num = e.target.currentValue;
startRound();
});
new Toggle({label:"PAUSE"})
.sca(.7)
.pos(200,30,LEFT,BOTTOM,interface)
.change(e=>{
timer.pause(e.target.toggled);
});
new Slider({
barLength:150,
min:1, max:.2,
button:"aztec",
useTicks:true,
step:.1,
currentValue:.6
})
.sca(1.1)
.pos(150,45,RIGHT,BOTTOM,interface)
.change(e=>{
timer.time = e.target.currentValue;
});
STYLE = {font:"impact", color:"#554d73"};
new Label("A-HA GAME!", 60)
.centerReg()
.loc(194, 210)
.rot(-45)
.animate({
from:true,
props:{scale:0},
time:.5,
ease:"backOut",
wait:.3
})
// .place();
new Label("PRESS SQUARE THAT DOES NOT CHANGE", 20)
.centerReg()
.alp(.6)
.loc(233, 232)
.rot(-45)
.animate({
from:true,
props:{scale:0},
time:.5,
wait:.6,
ease:"backOut"
})
// .place();
// make a Container for the top interface as well
// this was done after the creating the interfaces
// it just took a couple minutes to do this
// so we can animate these in together
// We could animate them individually if desired
// in which case, they would not have to be in a container
const scores = new Container(stageW, stageH)
.addTo()
.animate({
from:true,
props:{y:-300},
time:.7,
ease:"backOut",
wait:1.3
})
new Label("RIGHT").sca(.5).loc(880, 30, scores);
new Label("WRONG").sca(.5).loc(880, 150, scores);
STYLE = {};
const right = new Scorer({backgroundColor:"#A5A7BB"}).pos(50,50,RIGHT,TOP,scores)
const wrong = new Scorer({backgroundColor:"#A496A4"}).pos(50,170,RIGHT,TOP,scores)
// 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=Label
// https://zimjs.com/docs.html?item=Toggle
// https://zimjs.com/docs.html?item=Slider
// https://zimjs.com/docs.html?item=Dial
// https://zimjs.com/docs.html?item=change
// https://zimjs.com/docs.html?item=animate
// https://zimjs.com/docs.html?item=cur
// https://zimjs.com/docs.html?item=pos
// https://zimjs.com/docs.html?item=loc
// https://zimjs.com/docs.html?item=alp
// https://zimjs.com/docs.html?item=rot
// https://zimjs.com/docs.html?item=sca
// https://zimjs.com/docs.html?item=addTo
// https://zimjs.com/docs.html?item=removeFrom
// https://zimjs.com/docs.html?item=centerReg
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=place
// https://zimjs.com/docs.html?item=Tile
// https://zimjs.com/docs.html?item=Emitter
// https://zimjs.com/docs.html?item=shuffle
// 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=series
// https://zimjs.com/docs.html?item=lighten
// https://zimjs.com/docs.html?item=zog
// https://zimjs.com/docs.html?item=STYLE
// https://zimjs.com/docs.html?item=ANIMATE
// FOOTER
// call remote script to make ZIM icon - you will not need this
timeout(2, function(){
createIcon();
});
}); // end of ready
Also see: Tab Triggers