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.
<!-- annotaion in js -->
<div id="stage">
<svg id="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 600">
<g id="bg">
<rect width="1000" height="600" />
</g>
<g id="bug1" class="bug cls-1">
<g>
<rect class="cls-2" x="538.61672" y="240" width="52" height="58" />
<polygon class="cls-2" points="630.617 240 630.617 326.834 713.561 240 630.617 240" />
<polygon class="cls-2" points="538.617 406 498.617 406 498.617 240 476.217 240 286.439 440 523.778 440 590.617 370.043 590.617 328 538.617 328 538.617 406" />
</g>
</g>
<g id="bug2" class="bug cls-3">
<g>
<rect class="cls-2" x="252.82421" y="205" width="44.2" height="49.3" />
<polygon class="cls-2" points="331.024 205 331.024 278.809 401.527 205 331.024 205" />
<polygon class="cls-2" points="252.824 346.1 218.824 346.1 218.824 205 199.785 205 38.473 375 240.211 375 297.024 315.537 297.024 279.8 252.824 279.8 252.824 346.1" />
</g>
</g>
<g id="bug3" class="bug cls-4">
<g>
<rect class="cls-2" x="827.0317" y="270" width="36.4" height="40.6" />
<polygon class="cls-2" points="891.432 270 891.432 330.784 949.493 270 891.432 270" />
<polygon class="cls-2" points="827.032 386.2 799.032 386.2 799.032 270 783.352 270 650.507 410 816.645 410 863.432 361.03 863.432 331.6 827.032 331.6 827.032 386.2" />
</g>
</g>
<g id="bug4" class="bug cls-1">
<g>
<rect class="cls-2" x="827.0317" y="270" width="36.4" height="40.6" />
<polygon class="cls-2" points="891.432 270 891.432 330.784 949.493 270 891.432 270" />
<polygon class="cls-2" points="827.032 386.2 799.032 386.2 799.032 270 783.352 270 650.507 410 816.645 410 863.432 361.03 863.432 331.6 827.032 331.6 827.032 386.2" />
</g>
</g>
<g id="bug5" class="bug cls-3">
<g>
<rect class="cls-2" x="252.82421" y="205" width="44.2" height="49.3" />
<polygon class="cls-2" points="331.024 205 331.024 278.809 401.527 205 331.024 205" />
<polygon class="cls-2" points="252.824 346.1 218.824 346.1 218.824 205 199.785 205 38.473 375 240.211 375 297.024 315.537 297.024 279.8 252.824 279.8 252.824 346.1" />
</g>
</g>
<g id="bug6" class="bug cls-1">
<g>
<rect class="cls-2" x="827.0317" y="270" width="36.4" height="40.6" />
<polygon class="cls-2" points="891.432 270 891.432 330.784 949.493 270 891.432 270" />
<polygon class="cls-2" points="827.032 386.2 799.032 386.2 799.032 270 783.352 270 650.507 410 816.645 410 863.432 361.03 863.432 331.6 827.032 331.6 827.032 386.2" />
</g>
</g>
<g id="bug7" class="bug cls-4">
<g>
<rect class="cls-2" x="252.82421" y="205" width="44.2" height="49.3" />
<polygon class="cls-2" points="331.024 205 331.024 278.809 401.527 205 331.024 205" />
<polygon class="cls-2" points="252.824 346.1 218.824 346.1 218.824 205 199.785 205 38.473 375 240.211 375 297.024 315.537 297.024 279.8 252.824 279.8 252.824 346.1" />
</g>
</g>
<g id="bug8" class="bug line cls-5">
<g>
<rect class="cls-5" x="827.0317" y="270" width="36.4" height="40.6" />
<polygon class="cls-5" points="891.432 270 891.432 330.784 949.493 270 891.432 270" />
<polygon class="cls-5" points="827.032 386.2 799.032 386.2 799.032 270 783.352 270 650.507 410 816.645 410 863.432 361.03 863.432 331.6 827.032 331.6 827.032 386.2" />
</g>
</g>
<g id="bug9" class="bug line cls-6">
<g>
<rect class="cls-6" x="252.82421" y="205" width="44.2" height="49.3" />
<polygon class="cls-6" points="331.024 205 331.024 278.809 401.527 205 331.024 205" />
<polygon class="cls-6" points="252.824 346.1 218.824 346.1 218.824 205 199.785 205 38.473 375 240.211 375 297.024 315.537 297.024 279.8 252.824 279.8 252.824 346.1" />
</g>
</g>
</svg>
</div><!-- /#stage -->
/* annotation in js */
body {
overflow: hidden;
background-color: #222;
margin: 0; padding: 0;
}
#stage {
position: relative; top: 5%; left: 0;
height: 85%; width: 100%;
background-color: #111;
border: 0;
/* pointer-events: none; */
}
#svg {
background-color: #111;
}
/* --- svg defs styles --- */
.cls-2 { fill: #f2a42c; }
.cls-1 { opacity: 0.3; }
.cls-3 { opacity: 0.3; }
.cls-4 { opacity: 0.3; }
.cls-3 .cls-2 { fill: #bbc9ef; }
.cls-5, .cls-6 {
fill: none;
stroke-width: 0.47px;
}
.cls-5 { stroke: #cbd9df; }
.cls-6 { stroke: #9aa8ad; }
#bug8 rect,polygon, #bug9 rect,polygon { stroke-width: 0.37px; }
.bug { position: absolute; opacity: 0; }
console.clear();
// my first GSAP amimation... whee!! great stuff.
// dreamy background using the bug from a client logo.
// runs infinitely... when a layer dies it spawns a new one.
// works best in Firefox, half the CPU of Safari or Chrome.
// SVG exported from Illustrator, hence funky class names.
// hey, it's my first.
/* change this next value sensibly... */
var bcount = 5; // number of layers... 1 to 9
// "bcount" = bug count, i.e. logo bugs preloaded in the SVG
// layers should fade in slowly and float up the screen,
// slowly fading back out to zero on exit.
// what I'm testing is where the problem begins where
// layers disappear before finishing their timelines,
// i.e. before they fade out to zero. It's not a disaster,
// still looks cool, but would like to isolate / optimize.
// bcount 1 works perfectly. layers always fade out to 0.
// bcount 2 nearly all good, very occasional disappearence.
// bcount 3 start to get disappearing layer behavior
// ... little difference from ...
// bcount 9 disappearing often but looks cool. ;-)
// This may just be an observation of where things start to
// break down when you pile on computationally intensive layers.
// still, can't help noticing how well 9 layers performs.
// not significantly more CPU than 3 layers. nice.
// helpers round and rnd() below
// rnd() is for easy syntax of rnd(min, max, decimal precision)
if (bcount > 9) bcount = 9;
if (bcount < 1) bcount = 1;
function bugIn( n ) {
var el = $('#bug'+ n ),
tl = new TimelineLite(),
scl = rnd(1.9, 3.2, 3), // scale
dur = rnd(1.5, 4, 3), // master duration unit
totalDur = dur * 3, // x3 should work
// increasing this doesn't seem to help
xpos = rnd(-511, n * 30 - 130, 0), // init x
ypos = rnd(170, 101, 0), // init y
omax = rnd(0.11, 0.17, 3), // opacity max
pps = rnd(-47, -13, 0); // speed, pixels per second
// put longest tween, i.e. position, first then add opacity ones
tl.set( el, { opacity: 0, scale: scl, x: xpos, y: ypos })
.to( el, totalDur, { y: ypos + (pps * dur * 3), ease: Power0.easeNone } )
.to( el, dur, { opacity: omax, ease: Power0.easeNone }, 0)
.to( el, dur, { opacity: 0, ease: Power0.easeNone }, dur * 2);
return tl;
}
var bnum = 0; // counter
function newBug(bnum) {
console.log("bnum", bnum);
// bnum = ( ++bnum - 1 ) % bcount + 1; // keep counting from 1 to bcount
var tm = new TimelineMax({
onComplete: newBug,
onCompleteParams: [bnum]
});
tm.add( bugIn( bnum ));
return tm;
}
// start 'em up...
// while (bnum < bcount) newBug();
for (var i = 0; i < bcount; i++) {
newBug(i + 1);
}
// - - - - - - - -
// helpers
function round(val, dec) {
var mul = Math.pow(10, dec || 0);
return Math.round( parseFloat( val ) * mul) / mul;
}
function rnd(min, max, dec) {
dec != 0;
return round( Math.random() * (max - min) + min, dec );
}
TweenLite.onOverwrite = function(overwritten, overwriting, target, props) {
console.log("tween that was overwritten", overwritten);
console.log("tween that did the overwriting", overwriting)
console.log("the target of the overwritten tween", target);
console.log("properties that were overwritten", props);
}
Also see: Tab Triggers