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, 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;
// This ZIM example is at 10% the size of the delightful
// https://codepen.io/Adir-SL/pen/vYEaEgQ pen by Adir.
// Even if you remove the SVG, it is at 71%.
// And we think you will agree that ZIM is much more readable code.
// 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
// CODE HERE
// draw a backing rectangle
// note, alpha on border overlaps alpha on shape to still show border
new Rectangle(600,550,black,black,4,70).alp(.1).center();
// make a Nail class that extends a ZIM Container so we can put it on the stage
class Nail extends Container {
constructor(radius=20) {
// this calls the Container and sets its origin and registration in the middle
// like most circular items
super(-radius, -radius, radius*2, radius*2);
new Circle(radius, dark).addTo(this);
// make the half highlight on the top
new Circle({radius, color:silver, percent:50}).addTo(this).rot(-45);
new Circle(radius*.85, tin).centerReg(this);
new Rectangle(radius*2*.85, 3, dark).centerReg(this);
}
}
// tile nails
const radius = 16;
const num = 9;
const space = 20;
const tile = new Tile(new Nail(radius), num, num, space, space).center();
// loop through each nail and give it some adjustments
tile.loop(nail=>{
nail.mouseChildren = false; // so target in mousedown is on nail not part of nail
nail.getChildAt(3).rot(rand(-60,60)); // randomize the turn but leave highlight at top left
if (!mobile()) nail.cache().hov(.7).sha(); // cache will unify the hover alpha
});
// create a band each time we mousedown and move
let band = null;
let nail = null;
let bandEvent = null;
let f = 1.02; // the scale factor on the band radius compared to nail
let startPoint = null;
tile.on("mousedown", e=>{
nail = e.target;
startPoint = tile.localToGlobal(nail.x, nail.y); // get global location of nail
// create a shape to draw band in
band = new Shape().loc(startPoint).bot().ord(1).ble("difference"); // just above backing rectangle
// bandEvent = nail.on("pressmove", drawBand);
bandEvent = stage.on("stagemousemove", drawBand);
});
// use mouseX and mouseY as moving but then snapped x and snapped y on pressup
function drawBand(e, x, y) {
if (x==null) x = frame.mouseX;
if (y==null) y = frame.mouseY;
// get the length of the band to the x and y
// draw it horizontal and then rotate it to the x and y
let length = dist(startPoint.x, startPoint.y, x, y);
band.c().s(white).ss(5)
.a(0, 0, radius*f, 90*RAD, -90*RAD) // arc is in radians
.lt(length, -radius*f) // top band line is -radius in y
.a(length, 0, radius*f, -90*RAD, 90*RAD)
.lt(0, radius*f) // bottom band line is +radius in y
.rot(angle(startPoint.x, startPoint.y, x, y))
stage.update();
}
tile.on("pressup", e=>{
// nail.off("pressmove", bandEvent); // remove the pressmove event
stage.off("stagemousemove", bandEvent); // remove the pressmove event
// use hitTestGrid to get the index of the tile that the mouse is nearest
// width, height, cols, rows, x, y, offsetX, offsetY, spacingX, spacingY, local, type
let index = tile.hitTestGrid(tile.width, tile.height, num,num, frame.mouseX,frame.mouseY);
if (index!=null) { // do not use if (index) {} because index could be 0
// the drawBand is expecting a global position
// so convert the location of the nearest nail to global
let point = tile.getChildAt(index).localToGlobal(0,0);
drawBand(null, point.x, point.y);
} else {
band.removeFrom();
}
stage.update();
});
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=Shape
// https://zimjs.com/docs.html?item=Circle
// https://zimjs.com/docs.html?item=Rectangle
// https://zimjs.com/docs.html?item=Tile
// https://zimjs.com/docs.html?item=hitTestGrid
// https://zimjs.com/docs.html?item=loop
// https://zimjs.com/docs.html?item=sha
// https://zimjs.com/docs.html?item=loc
// https://zimjs.com/docs.html?item=bot
// https://zimjs.com/docs.html?item=ord
// https://zimjs.com/docs.html?item=alp
// https://zimjs.com/docs.html?item=ble
// https://zimjs.com/docs.html?item=hov
// https://zimjs.com/docs.html?item=rot
// 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=dist
// 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