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, green.darken(.2), green.darken(.7), "food.jpg", "https://assets.codepen.io/2104200/");
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
// create the page that will be magnified
const page = new Container(stageW, stageH)
.addTo()
.animate({
from:true,
props:{y:-700, rotation:-25},
ease:"backOut",
time:.45,
wait:.3,
call:makeCopy // make a copy once it is positioned (or would have to reset rotation on clone - no big deal)
});
new Rectangle(stageW, stageH, frame.color).addTo(page);
new Rectangle(stageW*.85, stageH*.7, darker).loc(60,60,page).sha(black.toAlpha(.3),10,10,10)
asset("food.jpg").sca(.4).loc(100,100,page);
STYLE = {color:lighter, labelWidth:500};
new Label("MMMM - Lovely Pasta!")
.loc(420,120,page);
Style.add({size:22, labelWidth:500});
new Label("Photo by Shania Pinnata\n\nThis quick and delicious pasta dish is the perfect way to use up a summer bounty of basil and tomatoes!\n\nDon't have a green thumb? Never fear! You can knock out this classic pasta dish in no time with a jar of prepared pesto sauce.")
.loc(420,180,page);
pizzazz.makeIcon("magnify", white)
.loc(440,425,page)
// .place() // drag item and see location in console F12
.expand() // make a clickable box around it with default 20 pixel padding
.alp(.7)
.hov(.9)
.tap(toggleMagnify);
STYLE = {};
new Label("press to magnify", 20, null, green).loc(470,410,page).tap(toggleMagnify);
// make magnifying glass
// put registration point on handle and snap drag to registration point
const mag = new Container()
.reg(0,300) // center of handle - added this after making mag
.drag({all:true, reg:true, onTop:false, slide:true}); // slide is optional
const mask = new Circle(194,white).addTo(mag);
const glass = new Circle(200,dark,light,4).center(mag);
const handle = new Rectangle(50,200,new GradientColor([grey,light,dark],[0,.5,1],0,0,50,0),dark,3,[0,0,10,10])
.pos(0,-190,CENTER,BOTTOM,mag,0)
mag.center().vis(false);
// duplicate the content, scale it and set its mask to the mask circle in the mag
let copy;
function makeCopy() {
copy = page
.clone()
.sca(2.5)
.setMask(mask,true)
.vis(false)
.noMouse(); // if you want the glass to be clickable - but mag jumps up...
locateCopy();
}
// optionally rotate magnifying glass
const rotationDamp = new ProportionDamp(0,stageW,-30,30); // baseMin, baseMax, targetMin, targetMax
rotationDamp.immediate(stageW/2);
// add rotation and positioning of copy as mag is moved
// with damping, use a Ticker not a pressmove
// so object still moves to final location when drag stops moving (and mouse is down)
// we add the Ticker on pressdown (same as mousedown) and remove it on pressup
// we remove it by the id that is declared outside so available to both event functions
let ticker;
mag.on("pressdown", ()=>{
ticker = Ticker.add(()=>{
// optionally rotate
mag.rotation = rotationDamp.convert(frame.mouseX);
locateCopy();
});
});
mag.on("pressup", ()=>{
Ticker.remove(ticker);
});
function locateCopy() {
// figure out where to put the copy
// find the center of the glass - at 0,0 inside mag
// and where this is on the page
let pagePoint = mag.localToLocal(0,0,page);
// place the registration point of the copy to this location
copy.reg(pagePoint.x, pagePoint.y);
// set the location of copy at the glass center
// usually this is easier as it is the registration point of the mag
// but we have moved the registration point to the handle
let glassCenter = mag.localToGlobal(0,0);
copy.loc(glassCenter);
}
// using vis() because addTo() and removeFrom() were flashing the masked content
function toggleMagnify() {
if (mag.visible) {
copy.vis(false);
mag.vis(false);
} else {
locateCopy();
mag.vis(true);
copy.vis(true);
}
stage.update();
}
// btw ZIM has accessibility too see
// https://zimjs.com/docs.html?item=Accessibility
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=Label
// https://zimjs.com/docs.html?item=tap
// https://zimjs.com/docs.html?item=drag
// https://zimjs.com/docs.html?item=animate
// https://zimjs.com/docs.html?item=sha
// 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=hov
// 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=removeFrom
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=place
// https://zimjs.com/docs.html?item=expand
// https://zimjs.com/docs.html?item=setMask
// https://zimjs.com/docs.html?item=GradientColor
// https://zimjs.com/docs.html?item=ProportionDamp
// https://zimjs.com/docs.html?item=darken
// https://zimjs.com/docs.html?item=toAlpha
// 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();
createGreet();
}); // end of ready
Also see: Tab Triggers