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, blue, 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
// Page is an easy way to get a gradient backdrop
// or could use GradientColor, RadialColor, BitmapColor for more specific special colors:
// new Rectangle(stageW, stageH, new GradientColor([blue, green], [0,1], 0,0, 0,stageH)).addTo();
new Page(stageW, stageH, blue, green).addTo();
// this is the Container that will be moved by Frame.follow()
// we put everything we want to move in here
// then we say what object in the container we want to keep in the middle (the blob)
// and the whole container will be moved to feature the object.
const scene = new Container().addTo();
// Made the squiggle in a couple minutes at https://zimjs.com/nio/paths.html
const hose = new Squiggle({
color:black,
points:[[-39.6,21.1,0,0,-55.5,10.6,55.5,-10.6],[46.8,53.9,0,0,-24.6,-7.4,45.8,13.8,"straight"],[85.7,22.8,0,0,28.1,0.8,-28.1,-0.8],[117.8,70,0,0,-49.9,38.8,23,-17.9,"straight"],[148.5,18.6,0,0,-22.3,2.1,20.1,-1.8,"straight"],[178.3,51.3,0,0,-22.8,11.3,20.3,-10.1],[224.4,38.4,0,0,-30.1,-26,30.1,26],[315.9,34.3,0,0,-53.9,-24.7,53.9,24.7]],
interactive:false
})
.sca(8) // make it nice and long!
// Squiggle and Blobs have a starting bounds
// but they do not change as a the objects are moved with bezier handles.
// In this case, we want to position objects at their ends (the gas pump and the handle)
// so we want proper bounds to easily place these.
// We can get good enough bounds with the following method.
// Usually we do not need to do this.
// Because we did not provide the Container bounds when we made it,
// The container will take the dimensions of what we put in it.
.approximateBounds()
.addTo(scene);
const pump = new Rectangle(400,900,black,null,null,[100,100,0,0])
// pos of 0 at the left would put the left of the gas pump at the left of the hose
// so move it over so it is mostly off the hose to the left
.pos(-350,0,LEFT,CENTER,scene);
const handle = new Rectangle(150,100)
// pos of 0 to the right would put the right of the handle to the right of the hose
// we want to move it more outside the region so that is a negative pos amount
// as a positive pos amount would be the distance of the right of the handle from the right of the hose
// so... normally when we pos things within a container it is easy - how far from the edge
// but if we want to pos something more outside the container - just use negative numbers
// There are many ways to place things in ZIM - see https://codepen.io/zimjs/pen/VwYWMEv
.pos(-130,-140,RIGHT,CENTER,scene)
.rot(30);
const ring = new Circle(50, clear, black, 20).pos(0,-50,CENTER,BOTTOM,handle);
const spout = new Rectangle(100,50).pos(-80,-10,RIGHT,CENTER,handle).rot(10);
const blob = new Blob({
color:black,
points:[[-59.5,-52.7,0,0,-59.1,28.2,59.1,-28.2,"mirror"],[100,0,0,0,0,-50,0,50,"mirror"],[-51.4,68.8,0,0,56,22.2,-56,-22.2,"mirror"]],
interactive:false
})
.reg(30)
.center(scene)
.mov(-300)
.sca(.2)
.animate({ // animate the scale at both ends
props:{scale:.8},
time:2,
rewind:true,
rewindWait:6,
loopWait:3,
loop:true
})
.animate({ // make the blob follow the hose
props:{path:hose},
time:10,
loop:true,
loopWait:3,
loopWaitCall:()=>{gas.spurt(40);} // spurt the emitter as the loop starts waiting
});
// wiggle the rotation of the points on the blob
loop(blob.pointControls, control=>{
control.wiggle("rotation", 0, 10, 30, .2, 1)
});
// coded changes to Blob and Squiggle need an update() - do this constantly in a Ticker function
Ticker.add(()=>{
blob.update();
});
// Here is the blob for a smoke puff - made at https://zimjs.com/nio/paths.html
// based on a cloud that is provided there
var puff = new Blob({
color:[white,lighter,moon],
borderColor:dark,
borderWidth:5,
points:[[-70.2,-20.4,0,0,-28.1,-14.9,-21.1,-33.5,"mirror"],[-63,-94.4,0,0,-27.2,15,27.2,-15,"mirror"],[4.6,-64.3,0,0,-1.8,-36,49.2,-33.4,"mirror"],[71.5,-29.2,0,0,6.2,-34.3,33.4,-17.6,"mirror"],[132.3,29.6,0,0,-0.4,-31.4,0.4,31.4,"mirror"],[52.1,60.3,0,0,37.5,46.1,-8.3,45.5,"free"],[-57.7,49.6,0,0,25,94,-27.4,28.2,"free"],[-131.1,29.6,0,0,7,26.8,-7,-26.8,"mirror"]],
interactive:false
}).approximateBounds(); // on mobile, emitter will cache blob so make sure bounds are correct
// emit the cloud puff - starting paused (we spurt in the animation call above)
const gas = new Emitter({
obj:puff,
startPaused:true,
interval:.1,
animation:{
set:{scale:0},
props:{scale:{min:.3, max:1}},
time:.3
},
gravity:-5,
random:{
alpha:{min:.3, max:.7}, // power of ZIM VEE
rotation:[0,180] // power of ZIM VEE, etc.
},
num:2,
force:2,
life:3,
layers:"random",
angle:{min:-90, max:0}
}).loc(spout, null, scene).mov(70,130);
// tell the frame to follow the blob (will do so by shifting the blob's container)
frame.follow(blob);
// FOOTER
// call remote script to make ZIM icon - you will not need this
createIcon();
// 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=Blob
// https://zimjs.com/docs.html?item=Page
// 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=pos
// https://zimjs.com/docs.html?item=loc
// https://zimjs.com/docs.html?item=mov
// https://zimjs.com/docs.html?item=rot
// https://zimjs.com/docs.html?item=reg
// https://zimjs.com/docs.html?item=sca
// https://zimjs.com/docs.html?item=addTo
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=Emitter
// https://zimjs.com/docs.html?item=GradientColor
// https://zimjs.com/docs.html?item=zog
// https://zimjs.com/docs.html?item=Ticker
}); // end of ready
Also see: Tab Triggers