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.
html {height:100%;}
body {background-image: linear-gradient(#ebcb35, #fb4758);}
const frame = new Frame("fit", 1024, 768, clear, clear);
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
// THIS IS ZIM CAT!
// and time has been changed to SECONDS
// this can be set back again using TIME = "ms"; // or "milliseconds"
// Flare is a ZIM shape that is handy for making... cups!
const cup = new Flare({
thickness:240,
angles:-90,
lengths:[15,30,500],
anglesA:[0,-45,8],
color:black
}).center().mov(0,50);
// the top of the cup is going to be called a couple times so store
// and padding is how much in from the sides of the cup to start the bubbles
const cupTop = cup.y-cup.height;
const padding = 180;
// make a bunch of bubbles
// these will have a blendMode ble() that cuts out what it is in top of
// right back to the canvas color which is clear so we see the css gradient
loop(50, function () {
let bubble = new Circle(rand(6,12)).ble("destination-out");
animateBubble(bubble);
});
// animate the bubble - which also gets called on the bubble again when it is done
function animateBubble(bubble, again) {
// the cup registration point is in the middle bottom (a Flare rotated upwards)
// after the first time (again) we want to position the bubble lower down (bottom 20%)
var x = cup.x-(cup.width-padding)/2+rand(cup.width-padding);
var y = cup.y-rand(cup.height-(again?cup.height*.8:0));
// this function gets the animation time based on how far bubble has to go
function getTime() {
return (bubble.y-cupTop)*rand(.01,.03);
}
// here is the animation - that could be done with GreenSock
// but ZIM has a great animation engine too!
// https://zimjs.com/animation/
// and many other features like https://zimjs.com/nio/ (path animation in ZIM 9)
bubble
.loc(x, y)
.animate({
props:{y:cupTop}, // animate to the top of cup
time:getTime, // time accepts ZIM VEE (Pick) value of a function
ease:"linear",
timeCheck:false, // zim has just changed over to seconds and longer times are triggering warnings
call:()=>{
// could just loop:true but looks better if new bubbles come in at bottom
bubble.stopAnimate(); // stop previous wiggle
animateBubble(bubble, true) // start the bubble again
}
})
// wiggle the bubbles x about the start x by 5-20 pixels in 2-4 seconds
.wiggle("x", bubble.x, 5, 20, 2, 4);
}
// lime
new Circle(80, yellow.lighten(.2), yellow.darken(.3), 20)
.loc(cup)
.mov(cup.width/2, -cup.height)
.bot(); // put at back
// sparkles
new Emitter({
// Poly(radius, sides, pointSize, color, borderColor, borderWidth...)
// note: {} and [] are ZIM VEE (Pick) values for dynamic parameters
obj:new Poly({min:10, max:15}, [5,6,7], 1, black, black, 2),
horizontal:true,
height:5,
angle:{min:-90-20, max:-90+20},
force:{min:2, max:4},
animation:{props:{rotation:["-360","360"]}, ease:"linear"},
shrink:false,
interval:{min:.1, max:.2}
}).loc(cup).mov(0,-cup.height);
new Label({text:"Happy Summer Drinks!", variant:true}).alp(.5).sca(.6).pos(30,30);
// to include a Teleporter in a ZIM app
// import https://zimjs.org/teleporter.js
// and pass in the URL of your CodePen page
const url = "https://codepen.io/zimjs/pen/rNewpwP";
const teleporter = new Teleporter(url).sca(.3).pos(30,20,LEFT,BOTTOM);
// To include a Teleporter on your HTML page see this Pen for an example
// https://codepen.io/zimjs/pen/WNxQPLp
// DOCS FOR ITEMS USED
// http://zimjs.com/docs.html?item=frame
// https://zimjs.com/docs.html?item=Circle
// https://zimjs.com/docs.html?item=Flare
// https://zimjs.com/docs.html?item=animate
// https://zimjs.com/docs.html?item=stopAnimate
// https://zimjs.com/docs.html?item=wiggle
// https://zimjs.com/docs.html?item=loop
// https://zimjs.com/docs.html?item=loc
// https://zimjs.com/docs.html?item=mov
// https://zimjs.com/docs.html?item=bot
// https://zimjs.com/docs.html?item=ble
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=Emitter
// https://zimjs.com/docs.html?item=darken
// https://zimjs.com/docs.html?item=lighten
// FOOTER
// call remote script to make ZIM icon - you will not need this
createIcon();
// createGreet();
}); // end of ready
Also see: Tab Triggers