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.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Parallax Plugin Demo</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="https://ianlunn.co.uk/plugins/jquery-parallax/scripts/jquery.parallax-1.1.3.js"></script>
<script type="text/javascript" src="https://ianlunn.co.uk/plugins/jquery-parallax/scripts/jquery.localscroll-1.2.7-min.js"></script>
<script type="text/javascript" src="https://ianlunn.co.uk/plugins/jquery-parallax/scripts/jquery.scrollTo-1.4.2-min.js"></script>
</head>
<body>
<ul id="nav">
<li><a href="#intro" title="Next Section"><img src="https://ianlunn.co.uk/plugins/jquery-parallax/images/dot.png" alt="Link" /></a></li>
<li><a href="#second" title="Next Section"><img src="https://ianlunn.co.uk/plugins/jquery-parallax/images/dot.png" alt="Link" /></a></li>
<li><a href="#third" title="Next Section"><img src="https://ianlunn.co.uk/plugins/jquery-parallax/images/dot.png" alt="Link" /></a></li>
<li><a href="#fifth" title="Next Section"><img src="https://ianlunn.co.uk/plugins/jquery-parallax/images/dot.png" alt="Link" /></a></li>
</ul>
<div id="intro">
<div class="story">
<div class="float-left">
<h2>(Almost) Static Background</h2>
<p>This section has a background that moves slightly slower than the user scrolls. This is achieved by changing the top position of the background for every pixel the page is scrolled.</p>
</div>
</div> <!--.story-->
</div> <!--#intro-->
<div id="second">
<div class="story"><div class="bg"></div>
<div class="float-right">
<h2>Multiple Backgrounds</h2>
<p>The multiple backgrounds applied to this section are moved in a similar way to the first section -- every time the user scrolls down the page by a pixel, the positions of the backgrounds are changed.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nibh erat, sagittis sit amet congue at, aliquam eu libero. Integer molestie, turpis vel ultrices facilisis, nisi mauris sollicitudin mauris, volutpat elementum enim urna eget odio. Donec egestas aliquet facilisis. Nunc eu nunc eget neque ornare fringilla. Nam vel sodales lectus. Nulla in pellentesque eros. Donec ultricies, enim vitae varius cursus, risus mauris iaculis neque, euismod sollicitudin metus erat vitae sapien. Sed pulvinar.</p>
</div>
</div> <!--.story-->
</div> <!--#second-->
<div id="third">
<div class="story">
<div class="float-left">
<h2>What Happens When JavaScript is Disabled?</h2>
<p>The user gets a slap! Actually, all that jQuery does is moves the backgrounds relative to the position of the scrollbar. Without it, the backgrounds simply stay put and the user would never know they are missing out on the awesome! CSS2 does a good enough job to still make the effect look cool.</p>
</div>
</div> <!--.story-->
</div> <!--#third-->
<div id="fifth">
<div class="story">
<p>Check out my new plugin <a href="http://www.sequencejs.com" title="Sequence.js">Sequence.js</a> for parallax effects and a whole lot more!</p>
<h2>Ian Lunn</h2>
<ul>
<li><strong>Twitter</strong>: <a href="https://www.twitter.com/IanLunn" title="Follow Ian on Twitter">@IanLunn</a></li>
<li><strong>GitHub</strong>: <a href="https://www.github.com/IanLunn" title="Follow Ian on GitHub">IanLunn</a></li>
<li><strong>Website</strong>: <a href="https://www.ianlunn.co.uk/" title="Ian Lunn Design">www.ianlunn.co.uk</a></li>
</ul>
<p>This demo is based on the <a href="http://www.nikebetterworld.com" title="Nike Better World">Nikebetterworld.com</a> website.</p>
<h2>Credits</h2>
<p>This plugin makes use of some scripts and images made by others:</p>
<ul>
<li><a href="https://flesler.blogspot.com/2007/10/jqueryscrollto.html" title="jQuery ScrollTo">jQuery ScrollTo</a></li>
<li><a href="https://downloads.dvq.co.nz/" title="Background Textures">Wooden and Pyschedlic Background Textures</a></li>
<li><a href="http://www.sxc.hu/photo/931435" title="Trainers Image">Trainers Image</a></li>
<li><a href="http://www.sxc.hu/photo/1015485" title="Basketball Image">Basketball Image</a></li>
<li><a href="http://www.sxc.hu/photo/563767" title="Bottles Image">Bottles Image</a></li>
</ul>
</div> <!--.story-->
</div> <!--#fifth-->
</body>
</html>
/*
Plugin: jQuery Parallax
Version 1.1.3
Author: Ian Lunn
Twitter: @IanLunn
Author URL: https://www.ianlunn.co.uk/
Plugin URL: https://www.ianlunn.co.uk/plugins/jquery-parallax/
License: http://creativecommons.org/licenses/by-sa/3.0/ (Attribution Share Alike). Please attribute work to Ian Lunn simply by leaving these comments in the source code or if you'd prefer, place a link on your website to https://www.ianlunn.co.uk/.
*/
@charset "utf-8";
/* CSS Document */
body{
margin: 0;
min-width: 980px;
padding: 0;
}
p{
margin: 0 0 20px 0;
}
p, ul{
font-family:"Proxima Nova Light", 'Helvetica Neue', Arial, Helvetica, sans-serif;
font-size-adjust:0.488;
font-weight:200;
font-style:normal;
}
img{
border: 0;
}
h1, #pixels{
font-family:"Museo 900", Verdana, serif;
font-size-adjust:0.40;
font-weight:700;
font-style:normal;
}
h2{
font-family:"Beau Sans Pro Book", Verdana, sans-serif;
font-size-adjust:0.531;
font-weight:500;
font-style:normal;
}
#header h1, #pixels{
color: #48941A;
}
.float-left{
float: left;
margin: 0 0 0 20px;
}
.float-right{
float: right;
margin: 0 20px 0 0;
}
.center{
font-size: 2.5em;
padding: 80px 0 0 0;
text-align: center;
}
#nav{
list-style: none;
position: fixed;
right: 20px;
}
#nav li{
margin: 0 0 15px 0;
}
#header, #intro, #second{
width: 100%;
}
#intro{
background:url(https://ianlunn.co.uk/plugins/jquery-parallax/images/firstBG.jpg) 50% 0 no-repeat fixed;
color: white;
height: 600px;
margin: 0 auto;
padding: 0;
}
#second{
background: url(https://ianlunn.co.uk/plugins/jquery-parallax/images/secondBG.jpg) 50% 0 no-repeat fixed;
color: white;
height: 1300px;
margin: 0 auto;
overflow: hidden;
padding: 0;
}
#second .bg{
background: url(https://ianlunn.co.uk/plugins/jquery-parallax/images/trainers.png) 50% 0 no-repeat fixed;
height: 1300px;
margin: 0 auto;
padding: 0;
position: absolute;
width: 900px;
z-index: 200;
}
#third{
background: url(https://ianlunn.co.uk/plugins/jquery-parallax/images/thirdBG.jpg) 50% 0 no-repeat fixed;
color: white;
height: 650px;
padding: 100px 0 0 0;
}
#fifth{
background: #ccc;
height: 400px;
margin: 0 auto;
padding: 40px 0 0 0;
}
.story{
margin: 0 auto;
min-width: 980px;
overflow: auto;
width: 980px;
}
.story .float-left, .story .float-right{
padding: 100px 0 0 0;
position: relative;
width: 350px;
}
$(document).ready(function(){
$('#nav').localScroll(800);
//.parallax(xPosition, speedFactor, outerHeight) options:
//xPosition - Horizontal position of the element
//inertia - speed to move relative to vertical scroll. Example: 0.1 is one tenth the speed of scrolling, 2 is twice the speed of scrolling
//outerHeight (true/false) - Whether or not jQuery should use it's outerHeight option to determine when a section is in the viewport
$('#intro').parallax("50%", 0.1);
$('#second').parallax("50%", 0.1);
$('.bg').parallax("50%", 0.4);
$('#third').parallax("50%", 0.3);
})
Also see: Tab Triggers