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.
<video autoplay id="video" style="display:none;" playsinline>
<source src="https://s3.amazonaws.com/zimjs/zimoncodepen_s.mp4?playsinline=1" type="video/mp4" />
</video>
const frame = new Frame("fit", 1024, 768, "#333", "#111");
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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This Pen is not just to show video in ZIM
// It is more so a greeting to you, the creative people in CodePen
// Please watch the content - hopefully to the end.
// You are very much invited to join us building with ZIM!
// We have a free, friendly forum at https://zimjs.com/slack
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This example is quite lengthy because the five control buttons
// to play video is really just a couple lines (STEP 4)
// where ZIM reads the video into a Bitmap (thanks CreateJS)
// and then we just use HTML 5 commands to work with the video
// that is playing in the ZIM Bitmap
// 1. get a reference to the video tag in the HTML
var source = zid("video"); // ZIM shortform for document.getElementById()
// 2. when the video is loaded create and animate in control buttons
let dialCheck = false;
var playButton, restartButton, soundButton, rotateButton, dial;
const controls = createControls()
.alp(0)
.animate({props:{alpha:1}, time:700, wait:1000}); // wait until player animates in
// 3. create a player Container that we will place the video in and spin it perhaps
const w = 640;
const h = 360;
const player = new Container(w, w)
.centerReg()
.mov(0,-30);
// 4. read the source of the video into a Bitmap and center in the player
const video = new Bitmap(source)
video.setBounds(0,0,w,h)
video.center(player).mov(6);
// 5. in this example we mask the video with a circle
const circle = new Circle(video.width/2-12, "#222")
.center(player, 0)
.sca(0)
.cur();
video.setMask(circle);
circle.animate({scale:1}, 3000, "elasticOut"); // animate after the mask is set
var pane = new Pane(500,150,"VIDEO ON CANVAS!",yellow).show();
pane.on("close", function () {
source.play();
controls.animate({props:{alpha:1}, time:.7, wait:1}); // wait until player animates in
});
// 6. clicking on the video will pause or play so update the button too
circle.on("click", ()=>{
playButton.toggle();
togglePlay();
});
// 7. add the play / pause functionality making use of the Button toggle functionality
playButton.on("click", togglePlay);
function togglePlay() {
if (playButton.toggled) {
source.pause();
} else {
source.play();
}
}
// 8. handle restart by setting source.currentTime = 0
restartButton.on("click", restart);
function restart() {
circle.animate({props:{scale:0}, time:1000, rewind:true, ease:"backIn", rewindCall:function() {
// player.rotation = 0;
source.currentTime = 0;
source.play();
playButton.toggle(false);
}});
}
// 9. handle sound muting with the source.muted property
soundButton.on("click", ()=>{
source.muted = soundButton.toggled;
});
var rotateEvent = rotateButton.on("click", ()=>{
if (!rotateButton.toggled) resetRotation();
});
function resetRotation(mode) {
rotateButton.off("click", rotateEvent);
rotateButton.enabled = false;
player.animate({rotation:0}, player.rotation%(360*3)*10, "backInOut", ()=>{
rotateButton.on("click", rotateEvent);
rotateButton.enabled = true;
if (mode == "end") {
source.currentTime = 0;
rotateButton.toggle(false);
playButton.toggle(true);
playButton.enabled = true;
}
});
}
// 10. handle what happens when the video ends with an ended event on the source
source.addEventListener("ended", restart);
// 11. animate the Dial to show video progress
Ticker.add(()=>{
// only have video set dial when dial is not in use
if (dial && !dialCheck && source.duration && source.duration>0) {
dial.currentValue = source.currentTime / source.duration;
}
if (rotateButton.toggled) player.rotation += .2;
});
function createControls() {
const iconScale = 1.2;
const iconColor = dark
const buttonSize = 80;
const buttonColor = silver;
const buttonRoll = green;
const controls = new Tile({
obj:series(
playButton = makeButton("pause", "play"),
restartButton = makeButton("restart"),
soundButton = makeButton("sound", "mute"),
rotateButton = makeButton("rotate", "stop"),
dial = new Dial({
min:0,
max:1,
step:0,
width:buttonSize,
backgroundColor:silver,
indicatorColor:dark
}).alp(.9)
),
cols:1,
rows:5,
spacingV:30,
clone:false
}).pos(40, 70, true);
function makeButton(type, toggle) {
let icon = pizzazz.makeIcon({
type:type,
color:iconColor,
scale:iconScale
});
let toggleIcon;
if (toggle) {
toggleIcon = pizzazz.makeIcon({
type:toggle,
color:iconColor,
scale:iconScale
});
}
let button = new Button({
width:buttonSize,
height:buttonSize,
backgroundColor:buttonColor,
rollBackgroundColor:buttonRoll,
gradient:.2,
corner:buttonSize/2,
icon:icon,
toggleIcon:toggleIcon
});
return button;
}
dial.inner.color = dark;
dial.backing.sha();
dial.on("mousedown", ()=>{
dialCheck = true;
dial.backing.color = green;
})
dial.on("pressup", ()=>{
dialCheck = false;
dial.backing.color = silver;
stage.update();
});
dial.on("change", ()=>{
source.currentTime = dial.currentValue * source.duration;
});
return controls;
}
new Button({
label:"SEE HD VID",
backgroundColor:blue,
rollBackgroundColor:pink,
width:300,
corner:[60,0,60,0]
}).sca(.7).pos(40,40,null,true).tap(()=>{
source.pause();
playButton.toggle(true);
zgo("https://youtu.be/a-qTs91kIug", "_blank");
}).animate({
wait:1500,
from:true,
props:{x:-400},
ease:"backOut",
time:500
});
new Label("ZIM VIDEO", 30, null, "#666")
.pos(60, 40).alp(0).animate({alpha:1}, 3000);
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=Bitmap
// https://zimjs.com/docs.html?item=Circle
// https://zimjs.com/docs.html?item=Label
// https://zimjs.com/docs.html?item=Button
// https://zimjs.com/docs.html?item=Pane
// https://zimjs.com/docs.html?item=Dial
// https://zimjs.com/docs.html?item=Tile
// https://zimjs.com/docs.html?item=tap
// https://zimjs.com/docs.html?item=animate
// https://zimjs.com/docs.html?item=cur
// 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=setMask
// https://zimjs.com/docs.html?item=zog
// https://zimjs.com/docs.html?item=zid
// https://zimjs.com/docs.html?item=zgo
// 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