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.
<section id="info">
<header>
<hgroup>
<h1>FoldScroll</h1>
<h2>Experimental CSS 3D scroll behavior</h2>
</hgroup>
<a href="https://github.com/soulwire/FoldScroll/zipball/master" target="_blank">Download</a>
<a href="https://github.com/soulwire/FoldScroll" target="_blank">View on Github</a>
</header>
<aside>
<p>Quotes from <a href="http://http://butdoesitfloat.com/" target="_blank">http://butdoesitfloat.com/</a></p>
</aside>
</section>
<section class="quotes">
<article>
<p>Technique is just a means of arriving at a statement</p>
<em>Jackson Pollock</em>
</article>
<article>
<p>Perhaps a human language is possible in which the intent of meaning is actually beheld in three-dimensional space</p>
<em>Terence Mckenna</em>
</article>
<article>
<p>All the virgin eyes in the world are made of glass</p>
<em>Mina Loy</em>
</article>
<article>
<p>We are intensely aware of man as a machine and the body as a mechanism</p>
<em>Oskar Schlemmer</em>
</article>
<article>
<p>It is already too late, and it will go on being even later</p>
<em>Alison Lurie</em>
</article>
<article>
<p>Science cannot be stopped. Man will gather knowledge no matter what the consequences - and we cannot predict what they will be</p>
<em>Linus Pauling</em>
</article>
<article>
<p>No one can witness the fall of the ice palace. It takes place at night, after all the children are in bed.</p>
<em>Tarjei Vesaas</em>
</article>
<article>
<p>The biological object is made of time as much as it is made of space and matter</p>
<em>Terence McKenna</em>
</article>
<article>
<p>The union of the mathematician with the poet, fervor with measure, passion with correctness, this surely is the ideal</p>
<em>William James</em>
</article>
<article>
<p>Mind is a captive of the body</p>
<em>Camille Paglia</em>
</article>
<article>
<p>Your order is meaningless, my chaos is significant</p>
<em>Nathaniel West via Amos Vogel</em>
</article>
<article>
<p>Every thing existing on the physical plane is an exteriorization of thought, which must be balanced through the one who issued the thought, and in accordance with that one's responsibility, at the conjunction of time, condition, and place</p>
<em>Harold W</em>
</article>
<article>
<p>I wanted to be alone in quite an unusual, new way. The very opposite of what you are thinking: namely, without myself…</p>
<em>Pirandello</em>
</article>
<article>
<p>I love forms beyond my own, and regret the borders between us</p>
<em>Loren Eiseley</em>
</article>
<article>
<p>The bedrock basic stratum of reality is irreality; the universe is irrational because it is built not on mere shifting sand - but on that which is not</p>
<em>Philip K Dick</em>
</article>
</section>
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html, body {
font-family: Consolas, monospace;
background: #f2f2f2;
padding: 0;
margin: 0;
}
/* Info */
#info {
font-size: 12px;
position: absolute;
z-index: 1;
color: #fff;
width: 260px;
left: 20px;
top: 20px;
}
#info a {
text-decoration: none;
border-bottom: 1px dotted rgba(255, 255, 255, 0.2);
color: rgba(255, 255, 255, 0.5);
}
#info a:hover {
color: #fff;
}
#info header, #info aside {
font-family: 'Play', sans-serif;
background: rgba(0, 0, 0, 0.8);
margin-bottom: 1px;
}
#info header {
padding: 12px 10px;
}
#info header hgroup h1 {
line-height: 22px;
font-weight: 300;
font-size: 18px;
margin: 0;
}
#info header hgroup h2 {
line-height: 14px;
font-weight: 300;
font-size: 12px;
color: rgba(255, 255, 255, 0.8);
margin: 0 0 6px 0;
}
#info header a {
text-transform: uppercase;
margin-right: 4px;
line-height: 20px;
font-size: 10px;
}
#info aside {
padding: 2px 10px;
}
/* Demo */
.quotes {
position: absolute;
bottom: 20px;
width: 100%;
left: 0;
top: 20px;
}
.quotes article {
border-bottom: 1px dashed #ddd;
text-align: justify;
line-height: 1.8;
background: #fff;
max-width: 620px;
font-size: 14px;
padding: 80px 40px;
margin: 0 auto;
width: 600px;
color: #333;
}
.quotes article em {
font-style: normal;
font-size: 12px;
color: #666;
}
.quotes article em:before {
content: '~';
margin: 0 10px;
}
(function($) {
$.fn.foldscroll = function( options ) {
// Constants
var PI = Math.PI;
var HALF_PI = PI / 2;
// Merge options & defaults
var opts = $.extend( {}, $.fn.foldscroll.defaults, options );
// Transformation template
var rot = 'perspective(' + opts.perspective + 'px) rotateX(θrad)';
// Main plugin loop
return this.each( function () {
var $this = $( this );
var $kids = $this.children();
var $item;
var $shading;
if ( opts.shading ) {
// Create an overlay for shading
$shading = $( '<span class="shading"/>' ).css({
background: opts.shading,
position: 'absolute',
opacity: 0.0,
height: '100%',
width: '100%',
left: 0,
top: 0
});
// Add shading to each child
$kids.each( function() {
$item = $(this);
$item.css( prefix({
'backface-visibility': 'hidden',
'transform-style': 'preserve-3d' // Fixes perspective in FF 10+
}));
// Make sure shading isn't already applied
if ( !$item.data( '_shading' ) ) {
$shading = $shading.clone();
// Prepare element
$item.css( 'position', 'relative' );
$item.data( '_shading', $shading );
$item.append( $shading );
}
});
}
// Prepare container
$this.css( prefix({ 'backface-visibility': 'hidden' }));
$this.css({ overflow: 'scroll' });
$this.on( 'scroll', function() {
// Store scroll amount
var st = $this.scrollTop();
// Store viewport properties
var vt = $this.offset().top - st;
var vh = $this.outerHeight();
var vb = vt + vh;
// Compute margin
var m = parseFloat( opts.margin );
m = m <= 1.0 ? Math.min( m, 0.5 ) : m / vh;
// Update children
$kids.each( function( index, el ) {
$item = $(this);
// Remove current transform
$item.css( prefix({ transform: 'none' }) );
// Cache shading element if it exists
$shading = $item.find( '.shading' ).hide();
// Store element properties
var et = $item.offset().top - st;
var eh = Math.max( m * vh, $item.outerHeight() );
var eb = et + eh;
// Highest start value
var a = Math.max( vt, et );
// Lowest end value
var b = Math.min( vb, eb );
// Do line segments overlap?
var show = a < b;
// If there's overlap
if ( show ) {
// compute overlap
var o = b - a;
var p = o / vh;
if ( p < m ) {
// normalise
p = p / m;
// direction
var d = et < vt ? 1 : -1;
// rotation
var t = ( 1 - p ) * HALF_PI * d;
// Contrain rotation
if ( Math.abs(t) <= HALF_PI ) {
// Apply rotation
$item.css( prefix({
'transform-origin': '50%' + ( et < vt ? '100%' : '0%' ),
'transform': rot.replace( 'θ', t )
}));
// Update shading overlay
if ( opts.shading )
$shading.css( 'opacity', 1.0 - p ).show();
} else {
show = false;
}
}
}
// Hide items outside of the viewport
$item.css( 'visibility', show ? 'visible' : 'hidden' );
});
});
// Set initial state
$this.trigger( 'scroll' );
});
};
// CSS3 vendor prefix helper
function prefix( obj ) {
var key, val;
for ( key in obj ) {
val = obj[ key ];
obj[ '-webkit-' + key ] = val;
obj[ '-moz-' + key ] = val;
obj[ '-ms-' + key ] = val;
obj[ '-o-' + key ] = val;
}
return obj;
}
// Default options
$.fn.foldscroll.defaults = {
// Perspective to apply to rotating elements
perspective: 600,
// Default shading to apply (null => no shading)
shading: 'rgba(0,0,0,0.2)',
// Area of rotation (fraction or pixel value)
margin: 0.2
};
})( jQuery );
$( '.quotes' ).foldscroll({
perspective: 900,
margin: '220px'
});
Also see: Tab Triggers