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 scaling = "fit"; // this will resize to fit inside the screen dimensions
const width = 1024;
const height = 768;
const color = dark; // ZIM has colors but you can use any HTML color "yellow", "#333", etc.
const outerColor = darker;
const assets = "createjs.png";
const path = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/2104200/"
const frame = new Frame(scaling, width, height, color, outerColor, assets, path);
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
// We are going to animate one Squiggle to match another Squiggle
// and then control these animations with a slider
// this will probably be integrated into ZIM animate over the next few releases...
// but it interesting to see what is under the hood.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// NOTE - since this was coded, ZIM has formalized Shape Tweens in ZIM 10.2.0
// see https://zimjs.com/animation/shapetween.html
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// made letter code here: http://zimjs.com/nio/paths.html
// we have letters for G R A N T and L A N N Y
// make sure each matching letter has the same number of points
// to make them morph into the other
// the type of point does not matter
// This looks like a lot of work but only took 5 minutes a letter
// and it is just cut and paste for the code - you never have to make the numbers
const grant = [
[[130.3,-10.5,0,0,19.3,49.8,-19.3,-49.8],[22.6,35.5,0,0,-6,-94.5,6,94.5],[135.9,38.5,0,0,-3,82.5,0,0,"free"],[79.2,38.2,0,0,0,0,0,0,"none"]],
[[41.8,105.8,0,0,-0.6,30,0.6,-30],[41.5,-39.2,0,0,-6,4,6,-4],[130.9,-8.3,0,0,-1,-42.8,1,42.8],[42.5,28.5,0,0,0,0,0,0,"none"],[98.2,35.5,0,0,-14.9,-8,14.9,8],[138.9,104.8,0,0,0,0,0,0,"none"]],
[[39.8,105.8,0,0,-0.6,30,0.6,-30],[78.3,-39.2,0,0,-39.8,0,39.8,0],[129.9,27.5,0,0,-1,-42.8,-30.8,1,"free"],[46.4,28.5,0,0,0,0,0,0,"none"],[130,27.5,0,0,0,0,0,0,"none"],[136.9,104.8,0,0,0,0,0,0,"none"]],
[[50.8,105.8,0,0,-0.6,30,0.6,-30],[56.5,-34.2,0,0,-16.9,1,16.9,-1],[128,96.2,0,0,-13.9,0,13.9,0],[134,-44.5,0,0,0,0,0,0,"none"]],
[[32.8,-31.4,0,0,0,0,0,0,"none"],[85.2,-31.2,0,0,0,0,0,0,"none"],[149.9,-33.2,0,0,0,0,0,0,"none"],[85.1,-31.2,0,0,0,0,0,0,"none"],[88.2,107.8,0,0,0,0,0,0,"none"]]
]; // expand this to see data
const lanny = [
[[54.8,-48.4,0,0,1.4,-17.8,-1.4,17.8],[54.5,11.5,0,0,0,-29.9,0,29.9],[55.4,93.1,0,0,0,-35.8,0,0,"free"],[156.9,93.8,0,0,0,0,0,0,"none"]],
[[38.8,105.8,0,0,-0.6,30,0.6,-30],[77.3,-39.2,0,0,-39.8,0,39.8,0],[128.9,27.5,0,0,-1,-42.8,-30.8,1,"free"],[45.4,28.5,0,0,0,0,0,0,"none"],[129,27.5,0,0,0,0,0,0,"none"],[135.9,104.8,0,0,0,0,0,0,"none"]],
[[48.8,105.8,0,0,-0.6,30,0.6,-30],[54.5,-34.2,0,0,-16.9,1,16.9,-1],[93.1,37.4,0,0,0,0,0,0,"none"],[127,93.2,0,0,-13.9,0,13.9,0],[136,15.6,0,0,0,0,0,0,"none"],[135,-46.4,0,0,0,0,0,0,"none"]],
[[51.8,-44.3,0,0,0.4,-29.7,-0.4,29.7],[62.5,93.2,0,0,-12.9,0,12.9,0],[130,-36.2,0,0,-13.9,0,13.9,0],[138,105.8,0,0,0,0,0,0,"none"]],
[[32.8,-31.4,0,0,0,0,0,0,"none"],[86.2,21.5,0,0,0,0,0,0,"none"],[149.9,-33.2,0,0,0,0,0,0,"none"],[87.1,20.5,0,0,0,0,0,0,"none"],[88.2,107.8,0,0,0,0,0,0,"none"]]
];
// We will make a Squiggle for each letter
// we will only animate the GRANT Squiggles
// and we animate each point and the two control handles
// to the location of the LANNY point and control handles
// so we will add both in the same position but hide the LANNY
// lines will be an array of Squiggles to animate (GRANT)
// points will be an array of all control points and handles
// that we are animating in the Squiggles
const lines = [];
const points = [];
// Could loop through the grant array and easily get each letter:
// loop(grant, (letter, i)=>{});
// but we need to get the matching lanny letter anyway
// so looping with the length and i seems a little more consistent
// as we get to apply i to grant and lanny the same way
// note that we are hiding lanny with an alpha of 0
loop(grant.length, i=>{
// tile each letter across the stage
let g = new Squiggle({interactive:false, points:grant[i], thickness:30}).loc(120+i*155, stageH/2-100);
let l = new Squiggle({interactive:false, points:lanny[i], thickness:30}).loc(120+i*155, stageH/2-100).alp(0);
// store the grant Squiggles in the lines array for later
lines.push(g);
// loop through each pointObject
// this is an array of parts of the points
loop(g.pointObjects, function (controls, i) {
// record a reference the matching pointObject of the lanny data
let target = l.pointObjects[i];
// loop through the first four elements of the points array
// the first element is the point container
// the second is the circle inside (we leave this alone)
// the third and forth are the two control rectangles
loop(4, (n) => {
// skip the circle
if (n==1) return;
// add the control to the points array for later
points.push(controls[n]);
// animate the control to the location of the lanny control
// this will animate the whole control container when n=0
// and the two rectangle control handles when n=2 and n=3
controls[n].animate({
props:{
x:target[n].x,
y:target[n].y
}
});
});
});
// throw in an extra color animation on each squiggle
g.animate({
props:{color:pink}
});
});
// pause the animations to let the slider control them
// this pauses all animations
pauseAnimate();
// circle.pauseAnimate() would pause animations on the circle
// pauseAnimate(true, "id"); would pause all animations with id of id
// circle.pauseAnimate(true, "id"); well... you get the idea
// we will set the percentComplete of the objects being animated
// to the slider's currentValue
// these are all the objects added to the points array
// and all the Squiggles in the lines array
// the Squiggles also need to be updated to show any manual changes
// note how nice ZIM loop is to work with
Ticker.add(function () {
loop(points, point=>{
point.percentComplete = slider.currentValue;
});
loop(lines, line=>{
line.percentComplete = slider.currentValue;
line.update();
});
});
// create the Slider with custom Button
const slider = new Slider({
min:0,
max:100,
barWidth:40,
button:new Button({
label:"",
backing:frame.asset("createjs.png").sca(.8).centerReg()
})
})
.center()
.mov(85,200)
// animate the slider's currentValue property
// this then is read in the Ticker
// to change the various animations
.animate({
props:{currentValue:100},
loop:true,
rewind:true,
time:2500,
rewindWait:500,
loopWait:500
});
// stop the Slider from being used when animating
// normally just slider.enabled=false would be fine
// seems to be a delay when adding cursor during slider creation
// so enabled false works but cursor still shows
// adding a timeout lets it work properly - sorry!
timeout(100, ()=>{slider.enabled = false});
// add a Button to toggle the Slider from manual to auto
// note the ZIM Button has toggle built in (plus lots more!)
new Button({
label:"MANUAL",
toggle:"AUTO",
corner:0,
backgroundColor:blue,
rollBackgroundColor:pink,
shadowBlur:4
})
.centerReg()
.sca(.7)
.loc(slider.x-150, slider.y)
.tap(e=>{
// could use an on("click", ()=>{})
// but tap is chainable so we don't even need a button var
slider.pauseAnimate(e.target.toggled);
slider.enabled = e.target.toggled;
// need to sync up animation with slider
// when we go back to auto...
// this is tricky with rewind and waits
// to set animation percent to current slider
// and I am brain dead!
// So just start at the beginning...
if (!e.target.toggled) slider.currentValue = slider.percentComplete = 0;
});
new Label({text:"ZIM - CreateJS Dedication - Grant, Lanny and Team!", color:"white"}).alp(.5).sca(.7).pos(30,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=Squiggle
// 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=tap
// https://zimjs.com/docs.html?item=animate
// https://zimjs.com/docs.html?item=pauseAnimate
// https://zimjs.com/docs.html?item=loop
// https://zimjs.com/docs.html?item=pos
// https://zimjs.com/docs.html?item=mov
// https://zimjs.com/docs.html?item=alp
// https://zimjs.com/docs.html?item=sca
// https://zimjs.com/docs.html?item=centerReg
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=loop
// https://zimjs.com/docs.html?item=timeout
// https://zimjs.com/docs.html?item=zog
// https://zimjs.com/docs.html?item=Ticker
// FOOTER
// call remote script to make ZIM Foundation for Creative Coding icon
createIcon(frame);
}); // end of ready
Also see: Tab Triggers