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.
<h1>Grid Using GreenSock <a href="https://greensock.com/timelinelite" target="_blank">TimelineLite</a></h1>
<button id="shuffle">Shuffle</button>
<button id="reorder">Reorder</button>
<button id="prepend">Prepend</button>
<button id="append">Append</button>
<button class="spacer"></button>
<button id="reset">Reset</button>
<div id="container"></div>
$box-size = 100px
$box-color = #9acd32
$button-color = #555
$background = #3a3a4d
$color = #efefef
body
margin 20px
background $background
font-family RobotoDraft, 'Helvetica Neue', Helvetica, Arial
h1
color $color
font-weight: normal
font-weight 300
margin-bottom 30px
a
color $color
border-bottom 2px solid $color
text-decoration none
padding-bottom 3px
&:hover
color $tile-color
border-color $box-color
#container
overflow hidden
clear both
width 720px
position relative
.box
display inline-block
float left
width $box-size
height $box-size
margin 5px
background $box-color
text-align center
font-size 20px
line-height 100px
position relative
border 1px solid rgba(0,0,0,0.5)
button
float left
width $box-size
margin 0px 5px 20px 5px
padding 10px 0px
font-size 16px
background $color
color $333
border none
&:hover
background darken($color, 10)
&.spacer
background $background
console.clear();
var boxes = [];
var numBoxes = 18;
var numBoxesToAdd = 6;
// Animation settings
var duration = 0.5; // length of time in secods for box to fade in
var delay = 0.03; // delay in secods before each new box appears
var tiles = [];
var ease = Back.easeOut.config(0.5);
var container = $('#container')[0];
$(document).ready(function () {
init();
$('#shuffle').click(function () {
reorderTiles(true);
});
$('#reorder').click(function () {
reorderTiles();
});
$('#prepend').click(function () {
prependBoxes(addBoxes(numBoxesToAdd));
});
$('#append').click(function () {
appendBoxes(addBoxes(numBoxesToAdd));
});
$('#reset').click(function () {
init();
});
});
function init () {
tiles = [];
boxes = [];
$('#container').empty();
createBoxes(numBoxes);
appendBoxes(boxes);
}
//
// REORDER TILES
// ====================================================================
function reorderTiles(shuffled) {
var total = tiles.length;
var i = total;
while (i--) {
var tile = tiles[i];
tile.x = tile.element.offsetLeft;
tile.y = tile.element.offsetTop;
container.removeChild(tile.element);
}
shuffled ? shuffle(tiles) : tiles.sort(sortOrder);
for (var i = 0; i < total; i++) {
var tile = tiles[i];
var lastX = tile.x;
var lastY = tile.y;
container.appendChild(tile.element);
tile.x = tile.element.offsetLeft;
tile.y = tile.element.offsetTop;
var dx = tile.transform.x + lastX - tile.x;
var dy = tile.transform.y + lastY - tile.y;
TweenLite.fromTo(tile.element, 1, { x: dx, y: dy }, {
x: 0,
y: 0,
ease: ease,
immediateRender: true
});
}
}
//
// CREATE TILE
// ====================================================================
function createTile(num, prepend) {
var add = prepend ? ["prependTo", "unshift"] : ["appendTo", "push"];
var tile = $("<div class='box'/>").text(num)[add[0]](container)[0];
TweenLite.set(tile, { x: "+=0" });
tiles[add[1]]({
transform: tile._gsTransform,
element: tile,
num: num,
x: tile.offsetLeft,
y: tile.offsetTop
});
return tile;
}
//
// SORT
// ====================================================================
function sortOrder(a, b) {
return a.num - b.num;
}
function createBoxes (num) {
for (var i = 0; i < num; i += 1) {
boxes.push(i + 1);
}
}
function addBoxes (num) {
var numBoxes = boxes.length;
var newBoxes = [];
for (var i = 0; i < num; i += 1) {
newBoxes.push(numBoxes + i + 1);
boxes.push(numBoxes + i + 1);
}
return newBoxes;
}
function appendBoxes (collection, isShuffle) {
var tl = new TimelineLite();
collection.forEach(function(num, i) {
var tile = createTile(num);
tl.from(tile, duration, {
opacity: 0,
scale: 0,
ease: Sine.easeIn
}, '-=' + (duration - delay));
});
}
function prependBoxes (collection) {
var tl = new TimelineLite();
collection.reverse().forEach(function (num, index) {
var tile = createTile(num, true);
tl.from(tile, duration, {
opacity: 0,
scale: 0,
ease: Sine.easeIn,
delay: -(delay * (index + 1))
}, '-=' + (duration - delay));
});
}
function shuffle (array) {
var currentIndex = array.length;
var temporaryValue;
var randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
Also see: Tab Triggers