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", 1200, 675, light, dark);
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
// make a container for the rings so we can easily hide and show
const rings = new Container(stageW, stageH).addTo();
// Style for Blobs
STYLE = {
showControls:false,
borderColor:series(blue, pink),
borderWidth:3,
points:2,
move:false,
controlType:"mirror",
center:rings
}
const b1 = new Blob().transformPoints("scale", 2).mov(-350,-30);
const b2 = new Blob().transformPoints("scale", 2).mov(350,-30);
// Style for Circles on Blobs
STYLE = {
radius:10,
color:series(blue, pink),
addTo:rings
}
const c1 = new Circle().animate({
props:{path:b1},
time:2000,
ease:"linear",
loop:true
});
const c2 = new Circle().animate({
props:{path:b2, percent:-100},
time:5000,
ease:"linear",
loop:true
});
// Style for Pen
STYLE = {
penType:"kitetail",
draggable:false,
color:series(pink,blue),
size:{min:5, max:30},
delayPick:true,
damp:false
}
const pen = new Pen().loc(halfway())
pen.paper.noMouse(); // so can click through to blob controls
pen.immediate(pen.x, pen.y); // otherwise draws there from 0,0
Ticker.add(() => {pen.loc(halfway());});
function halfway() {
// the loc of c1 + half the distance between c1 and c2
return {x:c1.x+(c2.x-c1.x)/2, y:c1.y+(c2.y-c1.y)/2};
}
// BOTTOM CONTROLS
// this type of thing on other frameworks is often put in datgui
// zim has the equivilant of datgui as well
// see the top right of https://codepen.io/zimjs/pen/ydaPer
// but we prefer seeing our interface - for instance here as well:
// https://zimjs.com/ornamate.html - quite an old version of ZIM
// and here is about as advanced as you will get
// drawing with generative art: https://codepen.io/danzen/pen/vYEzGNw
new Rectangle(stageW, 80, moon).pos(0,0,LEFT,BOTTOM);
// Style for bottom components
STYLE = {
corner:5,
type:{
Button:{
backgroundColor:yellow,
label:"CLEAR",
borderColor:white,
borderWidth:3,
scale:.7,
shadowColor:-1
},
Label:{
centerReg:{add:false},
color:grey,
size:20
},
Selector:{
paddingVertical:10,
selectedIndex:series(0,1,0)
},
Tile:{
cols:2,
spacingH:20
},
Slider:{
barLength:100,
max:5,
currentValue:1,
barColor:series(blue, pink),
borderColor:series(blue, pink),
borderWidth:3,
backgroundColor:faint,
rollBackgroundColor:"rgba(255,255,255,.3)"
}
}
}
// Create components and then add to Tile at bottom
const clear = new Button().tap(() => {
pen.clear();
});
const show = new Selector(
new Tile(series(
new Label("Show"),
new Label("Hide")
))
).change(() => {
rings.visible = show.currentItem.text=="Show";
stage.update();
});
const type = new Selector(
new Tile(series(
new Label("Line"),
new Label("Kite")
))
).change(() => {
let lookup = {Line:"line", Kite:"kitetail"}
pen.setPen(lookup[type.currentItem.text]);
});
const play = new Selector(
new Tile(series(
new Label("Play"),
new Label("Pause")
))
).change(() => {
pauseAnimate(play.currentItem.text=="Pause");
});
const speed1 = new Slider()
.change(() => {
c1.rate = speed1.currentValue;
});
const speed2 = new Slider()
.change(() => {
c2.rate = speed2.currentValue;
});
new Tile({
obj:series(show, speed1, type, clear, play, speed2, new Button().alp(0)),
cols:7,
spacingH:45,
clone:false
})
.pos(16, 16, CENTER, BOTTOM);
new Label("generative art - press and change ovals").pos(20,20).alp(.5);
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=Circle
// https://zimjs.com/docs.html?item=Rectangle
// https://zimjs.com/docs.html?item=Blob
// https://zimjs.com/docs.html?item=Label
// https://zimjs.com/docs.html?item=Button
// https://zimjs.com/docs.html?item=Slider
// https://zimjs.com/docs.html?item=Selector
// https://zimjs.com/docs.html?item=tap
// https://zimjs.com/docs.html?item=change
// https://zimjs.com/docs.html?item=noMouse
// https://zimjs.com/docs.html?item=animate
// https://zimjs.com/docs.html?item=pauseAnimate
// 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=alp
// https://zimjs.com/docs.html?item=addTo
// https://zimjs.com/docs.html?item=Tile
// https://zimjs.com/docs.html?item=transformPoints
// https://zimjs.com/docs.html?item=zog
// https://zimjs.com/docs.html?item=STYLE
// https://zimjs.com/docs.html?item=Ticker
// FOOTER
// call remote script to make ZIM icon - you will not need this
createIcon(null,null,icon=>{icon.mov(0,20)});
}); // end of ready
Also see: Tab Triggers