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 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.
<div class="buttons-wrapper">
<button class="play">Play</button>
<label for="set-start">Set start time: </label>
<select name="set-start" id="set-start">
<option value="0">0</option>
<option value="1">1 second</option>
<option value="2">2 seconds</option>
<option value="3">3 seconds</option>
<option value="4">4 seconds</option>
</select>
<label for="set-tween">Set tween time: </label>
<select name="set-tween" id="set-tween">
<option value="0">0.5 seconds</option>
<option value="1">1 second</option>
<option value="2">2 seconds</option>
<option value="3">3 seconds</option>
<option value="4">4 seconds</option>
</select>
</div>
<div class="data">
Tween status: <input type="text" name="tw-status" value="" readonly> Tween duration: <input type="text" name="tw-duration" value="" readonly>
<label for="twseek">Tween set seek(0) on Play?</label>
<input id="twseek" name="twseek" type="checkbox" value="1" checked />
</div>
<div class="data">
Timeline status: <input type="text" name="tl-status" value="" readonly> Timeline duration: <input type="text" name="tl-duration" value="" readonly>
<label for="tlseek">Timeline set seek(0) on Play?</label>
<input id="tlseek" name="tlseek" type="checkbox" value="1" checked />
</div>
<div id="stage-container" width="800" height="400" style="width: 800px; height: 400px;">
<div id="stage" width="800" height="400" style="width: 800px; height: 400px;">
<svg id="stage-svg-0" class="stage-svg" x="0" y="0" height="400" width="800">
<g id="gp-0" class="svg-wrapper" ref="0" x="50" y="50" height="170" width="170">
<svg id="svg-0" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 170 170" class="svg inline" height="170" width="170">
<path fill="#FFF" d="M85 170c-46.87 0-85-38.13-85-85S38.13 0 85 0s85 38.13 85 85-38.13 85-85 85z"/>
<path fill="none" stroke="#282D33" stroke-width="4" d="M93.312 108.145h16.16c6.685 0 12.103 4.796 12.103 10.714v13.39M44.242 132.25v-13.392c0-5.918 5.42-10.714 12.105-10.714h16.13M93.078 100.51v8.206l-10.17 10.872-10.17-10.872v-8.205M57.29 48.265c-2.11 3.162-3.614 6.763-4.343 10.633-4.207 2.49-7.025 6.986-7.025 12.135 0 4.558 2.22 8.592 5.64 11.19-.616 1.323-.966 2.76-.966 4.27 0 6.453 6.197 11.685 13.842 11.685.636 0 1.262-.036 1.874-.106M102.96 91.47c1.166.61 2.493.955 3.9.955 4.667 0 8.45-3.783 8.45-8.45 0-1.903-.186-3.308-1.25-4.722 3.64-2.578 5.564-7.092 5.564-11.815 0-6.16-4.027-11.388-9.648-13.355.106-.376-.496-3.37-2.087-6.02"/>
<path fill="none" stroke="#282D33" stroke-width="4" d="M105.16 66.653c.84-.307 1.744-.475 2.69-.475 4.318 0 7.82 3.502 7.82 7.82s-3.502 7.82-7.82 7.82M57.156 81.818c-4.318 0-7.818-3.5-7.818-7.82s3.5-7.82 7.818-7.82"/>
<path fill="none" stroke="#282D33" stroke-width="4" d="M106.976 65.69v11.892c0 14.166-11.483 25.65-25.65 25.65-14.164 0-25.648-11.484-25.648-25.65v-11.89M74.617 91.853c5.156 2.08 10.72 1.608 15.283-.818"/>
<path fill="none" stroke="#282D33" stroke-width="4" d="M72.52 49.55c-2.196 6.24-6.645 11.74-12.937 15.01-1.686.877-2.967 1.484-4.922 2.158M107.176 66.313c-11.058.62-24.47-2.95-29.73-14.33l-1.27-2.75M73.752 72.673h-4.675M92.492 72.673h-4.674M84.75 82.952h-5.033V70.01"/>
<path fill="none" stroke="#282D33" stroke-width="4" d="M107.48 49.55h-50v-12.5c15.772-7.726 34.23-7.726 50 0v12.5z"/>
<g fill="none" stroke="#282D33" stroke-width="4">
<path d="M82.482 35.48v10.433M87.7 40.696H77.265"/>
</g>
<g fill="none" stroke="#282D33" stroke-width="4">
<path d="M78.375 132.3l-7.225-23.54h-3.877l-4.11 7.146 5.507 4.905-4.188 4.35 3.427 7.14M87.35 132.3l7.224-23.54h3.877l4.113 7.146-5.508 4.905 4.187 4.35-3.427 7.14"/>
</g>
<rect width="100%" height="100%" fill="rgba(255,255,255,0"/>
</svg>
</g>
</svg>
</div>
</div>
html, body
font-family: sans-serif
.buttons-wrapper
display: block
width: 800px
margin: 0 auto
button
cursor: pointer
&.play
display: block
background: blue
color: white
border: 0
padding: 10px 20px
border-radius: 4px
font-size: 18px
margin-bottom: 5px
svg.stage-svg
position: absolute
left: 0
top: 0
.data
width: 800px
margin: 5px auto
#stage-container
position: relative
width: 800px
height: 400px
margin: 0 auto 15px
background: #000
border: 4px #6bc28c solid
.buttons
width: 800px
position: relative
display: block
margin: 10px auto
#stage
display: block
width: 800px
height: 400px
position: relative
background: transparent
position: relative
var tw,
tl = new TimelineMax(
{
paused: true,
onStart: function(){
$('input[name=tl-status]').val('started...');
$('input[name=tl-duration]').val('');
},
onComplete: function(){
$('input[name=tl-status]').val('finished');
$('input[name=tl-duration]').val(tl.duration());
}
}
);
function addTween() {
tw = TweenMax.to(
$('#gp-0'),
0.5,
{
x: 300,
y: 200,
onStart: function(){
$('input[name=tw-status]').val('started...');
$('input[name=tw-duration]').val('');
},
onComplete: function(){
$('input[name=tw-status]').val('finished');
$('input[name=tw-duration]').val(tw.duration());
}
});
tl.add(tw);
// tl.add(tw).repeat(-1);
}
function resetFields() {
$('input').val('');
}
function changeStartTime(val) {
tw.startTime(val);
tl.pause();
}
function changeTweenDuration(val) {
tw.duration(val);
}
$('.play').on("click", function(){
resetFields();
if($('input[name=twseek]').is(':checked')) {
tw.seek(0);
}
if($('input[name=tlseek]').is(':checked')) {
tl.seek(0);
}
tl.play();
console.log(tw.vars);
});
$('#set-tween').on("change", function(){
changeTweenDuration(parseFloat($(this).val()));
});
$('#set-start').on("change", function(){
changeStartTime(parseFloat($(this).val()));
});
addTween();
Also see: Tab Triggers