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, dark, 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
let stage = frame.stage;
let stageW = frame.width;
let stageH = frame.height;
// REFERENCES for ZIM at http://zimjs.com
// see http://zimjs.com/learn.html for video and code tutorials
// see http://zimjs.com/docs.html for documentation
// see https://www.youtube.com/watch?v=pUjHFptXspM for INTRO to ZIM
// see https://www.youtube.com/watch?v=v7OT0YrDWiY for INTRO to CODE
// CODE HERE
// Create a ZIM Tag() object to hold Zdog
const dogTag = new Tag(500,500)
.center()
.mov(0,-20)
.add("<canvas id=dog width=500 height=500></canvas>")
// .outline()
// Here is how we can get a grab cursor if we want
// dogTag.tag.style.cursor = "grab";
// in ZIM we normally would use .cur("grab")
// but Zdog is overlayed on ZIM so takes away cursor
// unless we do not use Zdog dragRotate
// and set dogTag.tag.style.pointerEvents = "none";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ZDOG - https://zzz.dog/
const dog = new Zdog.Illustration({
element: "#dog",
dragRotate: true
});
// will be dynamically creating color parts between two grey parts
// distance of top and bottom grey part from the center
const offset = 120;
// build in the z access as shapes face that way
// and then rotate the whole dog Illustration
// later around the x axis to see sides
const bunTop = new Zdog.Hemisphere({
addTo: dog,
diameter: 120,
stroke: false,
color: brown, // zim color
backface: "sienna", // html color in quotes
});
bunTop.translate.z = offset+30;
const top = new Zdog.RoundedRect({
addTo:dog,
width:200,
height:200,
fill:true,
cornerRadius:60,
stroke:30,
color:tin,
});
top.translate.z = offset;
const bot = new Zdog.RoundedRect({
addTo: dog,
width:150, // bottom of logo is smaller than top
height:150,
fill:true,
cornerRadius:60,
stroke:30,
color:tin,
});
bot.translate.z = -offset;
bot.translate.x = -20;
const bunBot = new Zdog.Hemisphere({
addTo: dog,
diameter: 120,
stroke: false,
color: brown,
backface: "sienna",
});
bunBot.translate.z = -offset-30;
bunBot.rotate.x = 180*Math.PI/180;
bunBot.translate.x = -20;
const colors = [pink, blue, orange, yellow, green];
const parts = []; // so can animate these later with a sequence
const separation = offset*2/(colors.length+1);
loop(colors, (color,i)=>{
let size = 40+i*20;
let part = new Zdog.RoundedRect({
addTo:dog,
width:size,
height:size,
fill:true,
cornerRadius:60,
stroke:30,
color:color,
});
// manipulating z and x to make slanted slats
part.translate.z = -offset+separation*(i+1);
part.translate.x = part.startX = size-100;
parts.push(part);
});
// render dog
Ticker.add(()=>{
dog.updateRenderGraph();
});
// end of Zdog
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
// rotate Zdog Illustration
// tip back 90 and then a full rotation
const startRotation = (90+360)*Math.PI/180;
animate({
target:dog,
// put dot animation in quotes
props:{"rotate.x":startRotation},
time:2000,
ease:"backOut",
wait:400
});
// will be animating multiple times
// otherwise would put this right in the animate() function
const animObj = {
target:parts,
// put dot animation in quotes
// put relative animation in quotes too ;-)
// usally this might be {x:100} to animate x to absolute 100
props:{"translate.x":"100"},
time:500,
loop:true,
rewind:true,
sequence:100,
id:"parts",
startPaused:true
}
animate(animObj);
// if we reset we will want a new animate()
// when we press the Animate CheckBox
// if we have not reset then we will
// want to pauseAnimate(false) the existing animation
let resetCheck = false;
const reset = new Button({
label:"RESET",
backgroundColor:blue,
rollBackgroundColor:green,
corner:0
})
.sca(.5)
.centerReg()
.pos(null, 60, null, true)
.mov(-20)
.tap(() => {
resetCheck = true;
// animate dog Illustration back to start
animate(dog, {
"rotate.x":startRotation,
"rotate.y":0,
"rotate.z":0
}, 600, "backOut");
// stop the parts animation and animate parts back to start
stopAnimate("parts");
loop(parts, part=>{
// part.resetTween(); // would jump to start position
animate(part, {"translate.x":part.startX}, 400);
});
checkBox.checked = false;
});
var checkBox = new CheckBox({label:"Animate", color:light})
.sca(.5)
.centerReg()
.loc(reset)
.mov(150)
.change(e=>{
// if we have reset then make a new animate()
if (resetCheck) {
resetCheck = false;
// initial animate starts paused - but do not want that now
animObj.startPaused = false;
animate(animObj);
} else {
// otherwise we pause or unpause the existing animation
pauseAnimate(!checkBox.checked, "parts");
}
});
new Label({
text:"ZIM Burger - drag rotate the Zdog Illustration",
color:silver
}).center().pos(null,30);
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=Label
// https://zimjs.com/docs.html?item=Button
// https://zimjs.com/docs.html?item=CheckBox
// https://zimjs.com/docs.html?item=Tag
// https://zimjs.com/docs.html?item=tap
// https://zimjs.com/docs.html?item=change
// https://zimjs.com/docs.html?item=animate
// https://zimjs.com/docs.html?item=stopAnimate
// https://zimjs.com/docs.html?item=pauseAnimate
// https://zimjs.com/docs.html?item=loop
// https://zimjs.com/docs.html?item=cur
// 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=sca
// https://zimjs.com/docs.html?item=outline
// https://zimjs.com/docs.html?item=centerReg
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=zog
// https://zimjs.com/docs.html?item=Ticker
// FOOTER
// Please see a greeting message - then come visit us at ZIM https://zimjs.com
createGreet(100);
// call remote script to make ZIM Foundation for Creative Coding icon
createIcon(50);
}); // end of ready
Also see: Tab Triggers