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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<link href='https://fonts.googleapis.com/css?family=Asap:400,700' rel='stylesheet' type='text/css'>
<div id="main">
<svg id="stage" version="1.1" xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="800" height="300" viewBox="0 0 800 300">
<style>
#stage {
background: #000;
}
#type-container {
position: relative;
width: 800px;
height: 300px;
background-color: #000;
margin: auto;
overflow: hidden;
}
#type-container h3 {
position: absolute;
font-family: 'Asap', sans-serif;
font-weight: 700;
margin: 0;
padding: 0;
width: 800px;
text-align: center;
visibility: hidden;
font-size: 120px;
top: 65px;
color: #ffffff;
}
</style>
<foreignobject class="node" x="0" y="0" width="800" height="300">
<div id="type-container"></div>
</foreignObject>
</svg>
<div id="form-wrapper">
<button id="process">REBUILD</button>
<button id="play">PLAY</button>
<button id="pause">PAUSE</button>
<button id="process-images">PROCESS IMAGES</button>
<textarea id="copy" name="copy" id="" cols="70" rows="2">
No one knows where the wind blows.
</textarea>
</div>
<div id="test-blobs"></div>
</div>
#main
// background-color: #fff
// color: #ffffff
min-height: 200vh
// #type-container
// position: relative
// width: 800px
// height: 300px
// background-color: #000
// margin: auto
// overflow: hidden
// #type-container h3
// position: absolute
// font-family: 'Asap', sans-serif
// font-weight: 700
// margin: 0
// padding: 0
// width: 800px
// text-align: center
// visibility: hidden
// font-size: 120px
// top: 65px
textarea
display: block
background: #003806
color: burlywood
font-size: 14px
border: 2px solid burlywood
padding: 10px
button
background: green
box-shadow: none
color: white
border: none
padding: 6px 20px
border-radius: 5px
margin: 0 0 10px 0
#test-blobs img
display: inline-block
max-width: 200px
margin-right: 3px
var container = $('#type-container'),
_sentenceEndExp = /(\.|\?|!)$/g, //regular expression to sense punctuation that indicates the end of a sentence so that we can adjust timing accordingly
sentences = "",
stage = $('stage'),
fo = stage.find('foreignObject'),
tl = new TimelineMax({paused: true});
// the animation
function machineGun(text) {
var words = text.split(" "),
time = 0,
word, wordCount, element, duration, isSentenceEnd, i;
wordCount = words.length;
for(i = 0; i < wordCount; i++){
word = words[i];
isSentenceEnd = _sentenceEndExp.test(word);
element = $("<h3>" + word + "</h3>").appendTo(container);
// element = document.createElementNS("http://www.w3.org/1999/xhtml","h3");
// element.innerHTML = word;
// container.appendChild(element);
duration = Math.max(0.5, word.length * 0.08); //longer words take longer to read, so adjust timing. Minimum of 0.5 seconds.
if (isSentenceEnd) {
duration += 0.6; //if it's the last word in a sentence, drag out the timing a bit for a dramatic pause.
}
//set opacity and scale to 0 initially. We set z to 0.01 just to kick in 3D rendering in the browser which makes things render a bit more smoothly.
TweenLite.set(element, {autoAlpha:0, scale:0, z:0.01});
//the SlowMo ease is like an easeOutIn but it's configurable in terms of strength and how long the slope is linear. See https://www.greensock.com/v12/#slowmo and https://api.greensock.com/js/com/greensock/easing/SlowMo.html
tl.to(element, duration, {scale:1.2, ease:SlowMo.ease.config(0.25, 0.9)}, time)
//notice the 3rd parameter of the SlowMo config is true in the following tween - that causes it to yoyo, meaning opacity (autoAlpha) will go up to 1 during the tween, and then back down to 0 at the end.
.to(element, duration, {autoAlpha:1, ease:SlowMo.ease.config(0.25, 0.9, true)}, time);
time += duration - 0.05;
if (isSentenceEnd) {
time += 0.6; //at the end of a sentence, add a pause for dramatic effect.
}
}
}
// utility stuff
function clearContent() {
$('#test-blobs').empty();
var containerContents = document.querySelectorAll('#type-container h3');
for ( let content of containerContents ) {
container[0].removeChild(content);
}
}
document.getElementById("process").onclick = function() {
clearContent();
sentences = $('#copy').val();
machineGun(sentences);
}
document.getElementById("play").onclick = function() {
tl.seek(0).play();
}
document.getElementById("pause").onclick = function() {
tl.pause();
}
document.getElementById("process-images").onclick = function() {
processImages();
}
$(function(){
console.clear();
sentences = $('#copy').val();
machineGun(sentences);
});
// process images
function processImages() {
$('#test-blobs').empty();
var FPS = 60;
TweenMax.ticker.fps(FPS);
var duration = tl.duration(),
frames = Math.ceil(duration / 1 * FPS),
current = 0,
masterSVG = document.getElementById('stage');
function buildSvgImageUrl(svg) {
var b64 = window.btoa(svg);
return "data:image/svg+xml;base64," + b64;
}
processImage();
function processImage() {
var canvas = document.createElement("canvas");
canvas.width = 800;
canvas.height = 300;
var ctx = canvas.getContext("2d");
tl.progress(current++ / frames);
var xml = new XMLSerializer().serializeToString(masterSVG);
var img = new Image();
img.crossOrigin = "Anonymous";
img.onload = function() {
ctx.drawImage(img, 0, 0);
var url = canvas.toDataURL("image/png");
var png = new Image();
png.src = url;
png.crossOrigin = "Anonymous";
$('#test-blobs').append(png);
URL.revokeObjectURL(url);
if (current <= frames) {
processImage();
}
};
// img.src = URL.createObjectURL(blob);
img.src = buildSvgImageUrl(xml);
img.onerror = function(error) {
console.log(error);
processImage();
}
}
}
/* learn more about the GreenSock Animation Platfrom (GSAP) for JS
https://www.greensock.com/gsap-js/
watch a quick video on how TimelineLite allows you to sequence animations like a pro
https://www.greensock.com/sequence-video/
*/
//Check out this enhanced version that intelligently groups words together: https://codepen.io/GreenSock/pen/sxdfe
Also see: Tab Triggers