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.
<!--
I did all the art. You can read the full version here: http://rachelnabors.com/alice-in-videoland/book
At the very end are links to the github repo + 2 tutorial articles I wrote about how I did it :D
--> <div class="alice-falling"></div>
<div id="skrollr-body">
<div id="tunnel" class="frightened">
<div class="page page_falling falling_frightened" data-mood="frightened">
<p>Either the well was very deep or she fell very slowly, for she had plenty of time to look about her on the way down.</p>
</div>
<div class="page page_falling falling_curious" data-mood="curious">
<p>At first it was too dark for her to see anything, but as her eyes adjusted, she could make out what seemed to be cupboards, bookshelves, paintings, lining the walls she was rushing past. </p>
</div>
<div class="page page_falling falling_bored" data-mood="bored">
<p>Down, down, down she fell. Would it never come to an end? She began to wonder how many miles she’d fallen and whether she’d end up at the center of the Earth—or come out the other side!</p>
</div>
<div class="page page_falling falling_sleeping" data-mood="sleeping">
<p>How would she call her sister? What if she didn’t speak the language? What if they couldn’t understand her and put her in an orphanage? She’d never see her sister or her cat again!</p>
</div>
<div class="page page_falling falling_waking" data-mood="waking">
<p>Poor Tuna! Would they remember to clean his litter box or give him his kibble? If only Tuna were with her now. There were no mice to live on in the air, but perhaps he could catch a bat. </p>
</div>
<!-- Wait 3 seconds or so for the video to end. Then return to the scene -->
<div class="page page_falling falling_weird" data-mood="weird">
<p>Before she could worry too much, her eyes grew heavy and she began to nod off whispering, “Do cats eat bats?” to no one in particular.</p>
</div>
<div class="page page_falling falling_aftermath" data-mood="jolted">
<p>She must’ve been dreaming, because for a moment she imagined he was there with her, as large as her sister.</p>
</div>
<div class="page page_falling falling_lookit-cat" data-mood="jolted"></div>
<div class="page page_falling falling_cat-reveal" data-mood="jolted"></div>
<div class="page page_falling falling_cat-out" data-mood="jolted">
<p>“Oh yes, cats eat bats all the time. You wouldn’t happen to be a bat, now would you?”</p>
</div>
</div>
</div><!--/#tunnel-->
#tunnel {
position: relative;
top: 0; left: 0;
background: url(https://assets.codepen.io/641/bg-tunnel-border-left.svg) 0 0 repeat-y, url(https://assets.codepen.io/641/bg-tunnel-border-right.svg) 100% 0 repeat-y, url(https://assets.codepen.io/641/bg-tunnel-furniture-comp900.svg) top center repeat-y, url(https://assets.codepen.io/641/bg-tunnel-specks.png), #6c373f;
background-size: 20px 150px, 20px 150px, 80% auto, auto auto;
}
.page {
/* Each page has a 3/4 ratio */
padding-top: 75%;
/* Hide the text */
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
.alice-falling {
background-image: url(https://assets.codepen.io/641/alice-fall.png);
background-size: 100% auto;
width: 31.25%;
padding-top: 48.73047%;
top: -10%;
left: 50%;
margin-left: -15.625%;
position: fixed;
z-index: 20;
}
.curious .alice-falling {
background-position: 0 20%;
}
.bored .alice-falling {
background-position: 0 80%;
}
.sleeping .alice-falling {
background-position: 0 60%;
}
.waking .alice-falling {
background-position: 0 100%;
}
.weird .alice-falling {
background-position: 0 0;
}
.jolted .alice-falling {
background-position: 0 40%;
}
@keyframes freak-out {
0% {
background-position: 0 0;
}
100% {
background-position: 0 200%;
}
}
.frightened .alice-falling {
animation: freak-out 1.5s steps(2) infinite;
background: url(https://assets.codepen.io/641/alice-frightened.png) 0 0 no-repeat;
background-size: 100% auto;
}
$(window).load(function() {
// How to guess which frame is "being read".
var beingRead = function() {
// It would be approximately centered, of equal distance from top as from bottom.
var $screenHeight = $.waypoints('viewportHeight');
var $pageHeight = $(".page").height();
var offset = ($pageHeight - $screenHeight) / 2 * -1;
return offset;
}
// calculate the height of the tunnels
var tunnelTop = Math.round($("#tunnel").offset().top);
var tunnelTopData = "data-" + tunnelTop;
var tunnelBottomData = "data-" + (tunnelTop + Math.round($("#tunnel").height()));
// Give Falling Alice her skrollr measurements as data attributes
$(".alice-falling").attr(tunnelTopData, "top:-10%").attr(tunnelBottomData, "top:80%");
//Start up the skrollr object
skrollr.init({
forceHeight: false
});
$(".page").waypoint(function(direction) {
var mood = $(this).data("mood");
$("body").removeClass().addClass(mood);
if (direction === "up") { // if scrolling up
$(this).addClass("in-view").removeClass("scrolled-past")
.waypoint('next').removeClass("in-view");
} else { // else, assuming we're not scrolling at all or are scrolling down
$(this).addClass("in-view").removeClass("scrolled-past")
.waypoint('prev').removeClass("in-view").addClass("scrolled-past");
}
}, {
offset: beingRead()
});
});
Also see: Tab Triggers