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 URL's 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 it's URL and the proper URL extention.
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.
<main>
<article id="container1">
<div id="clouds">
<div class="d1 background cloud1"></div>
<div class="d1 background cloud2"></div>
<div class="d1 background cloud3"></div>
<div class="d4 background cloud1"></div>
<div class="d1 background cloud2"></div>
<div class="d1 background cloud3"></div>
<div class="d2 midground cloud2"></div>
<div class="d4 foreground cloud1"></div>
<div class="d2 midground cloud2"></div>
<div class="d4 midground cloud3"></div>
<div class="d2 midground cloud3"></div>
<div class="d2 foreground cloud1"></div>
<div class="d3 foreground cloud1"></div>
<div class="d4 foreground cloud1"></div>
<div class="d3 foreground cloud1"></div>
<div class="d3 foreground cloud3"></div>
<div class="d3 midground cloud3"></div>
<div class="d3 foreground cloud2"></div>
<div class="d3 foreground cloud2"></div>
<div class="d4 midground cloud3"></div>
</div>
</article>
<article id="container2">
<div id="trainWindow">
<svg id="sky" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1024 576">
<defs>
<style>
.sky {
fill: url(#sky-gradient);
}
</style>
<linearGradient id="sky-gradient" x1="512" y1="576" x2="512" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#00bdff"/>
<stop offset="1" stop-color="#5fd6ff"/>
</linearGradient>
</defs>
<rect class="sky" width="1024" height="576"/>
</svg>
<svg id="cloud1" class="clouds" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 101.6 61.5">
<path d="M101.6,19.7a9.2,9.2,0,0,0-15.9-6.2,10.9,10.9,0,0,0-19.3-1.4,11.9,11.9,0,0,0-8.8-3.9H55.8a20.2,20.2,0,0,0-36.5,8.9H17.6A17.6,17.6,0,1,0,27,49.6,14.6,14.6,0,0,0,55.9,45,14,14,0,0,0,74,38.9,14.9,14.9,0,0,0,99.5,25.6,9.1,9.1,0,0,0,101.6,19.7Z"/>
</svg>
<svg id="cloud2" class="clouds" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 92.3 46.3">
<path d="M77,11.7a15.2,15.2,0,0,0-8.4,2.5A12,12,0,0,0,50.3,9.1,15.8,15.8,0,0,0,21,11a13.3,13.3,0,1,0-.7,22.2A8.2,8.2,0,0,0,27.1,40a12.2,12.2,0,0,0,20.1,1.9,11.6,11.6,0,0,0,10.2-2.3,13.3,13.3,0,0,0,11.7.4A15.3,15.3,0,1,0,77,11.7Z"/>
</svg>
<svg id="cloud3" class="clouds" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 113.8 51.6">
<path d="M113.8,13.3A6.4,6.4,0,0,0,103,8.7a12,12,0,0,0-10.6-1,8,8,0,0,0-10.5.5A14.7,14.7,0,0,0,56,7.2a11.2,11.2,0,0,0-11.2.7,13.7,13.7,0,0,0-22.5-.7,11.7,11.7,0,0,0-9-1.3,6.7,6.7,0,1,0-8.1,7.4A11.7,11.7,0,0,0,6.7,23.9a19.1,19.1,0,1,0,35,15A10,10,0,0,0,55,33a11.8,11.8,0,0,0,19.1-2.3,6.7,6.7,0,0,0,11.7-2.5,6.6,6.6,0,0,0,3.4.9h1.1a12,12,0,0,0,18.4-9.4A6.4,6.4,0,0,0,113.8,13.3Z"/>
</svg>
<svg id="grass" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1024 148.3">
<defs>
<style>
.grass {
fill: url(#grass-gradient);
}
</style>
<linearGradient id="grass-gradient" x1="512" x2="512" y2="148.26" gradientUnits="userSpaceOnUse">
<stop offset="0.26" stop-color="#009400"/>
<stop offset="1" stop-color="#493600"/>
</linearGradient>
</defs>
<rect class="grass" width="1024" height="148.26"/>
</svg>
<svg id="hill1" class="hills" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 372.2 205">
<defs>
<style>
.hill {
fill: url(#hill-gradient);
}
</style>
<linearGradient id="hill-gradient" x1="186.12" y1="205.01" x2="186.12" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#009400"/>
<stop offset="0.64" stop-color="#49b600"/>
</linearGradient>
</defs>
<path class="hill" d="M372.2,205H0C0,91.8,83.3,0,186.1,0S372.2,91.8,372.2,205Z"/>
</svg>
<svg id="hill2" class="hills" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 280.1 205">
<path class="hill" d="M280.1,205H0C0,91.8,62.7,0,140,0S280.1,91.8,280.1,205Z"/>
</svg>
<svg id="hill3" class="hills" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 229.2 178.1">
<path class="hill" d="M229.2,178.1H0C0,79.8,51.3,0,114.6,0S229.2,79.8,229.2,178.1Z"/>
</svg>
<svg id="hill4" class="hills" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 328.1 249.2">
<path class="hill" d="M328.1,249.2H0C0,111.6,73.4,0,164,0S328.1,111.6,328.1,249.2Z"/>
</svg>
<svg id="hill5" class="hills" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 323.1 154.7">
<path class="hill" d="M323.1,154.7H0C0,69.3,72.3,0,161.5,0S323.1,69.3,323.1,154.7Z"/>
</svg>
<svg id="hill6" class="hills" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 372.2 205">
<path class="hill" d="M372.2,205H0C0,91.8,83.3,0,186.1,0S372.2,91.8,372.2,205Z"/>
</svg>
<svg id="powerline" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 57.6 511.5">
<defs>
<style>
.powerline {
fill: url(#powerline-gradient);
}
</style>
<linearGradient id="powerline-gradient" y1="255.73" x2="57.6" y2="255.73" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#493600"/>
<stop offset="0.28" stop-color="#523e00"/>
<stop offset="0.64" stop-color="#493600"/>
<stop offset="1" stop-color="#3f2900"/>
</linearGradient>
</defs>
<title>powerline</title>
<path class="powerline" d="M0,511.5V28.8A28.9,28.9,0,0,1,28.8,0h0A28.9,28.9,0,0,1,57.6,28.8V511.5Z"/>
</g>
</svg>
<svg id="Train" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1024 576">
<defs>
<style>
.cls-1 {
fill: url(#linear-gradient);
}
.cls-2 {
fill: #fff;
opacity: 0.2;
}
.cls-3 {
fill: url(#linear-gradient-2);
}
.cls-4 {
fill: url(#linear-gradient-3);
}
.cls-5 {
fill: #b2b17b;
opacity: 0.3;
}
.cls-6 {
fill: #adaa79;
}
.cls-7 {
fill: #d8d893;
}
.cls-8 {
fill: #efe8ab;
}
</style>
<linearGradient id="linear-gradient" x1="512" y1="576.96" x2="512" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#dbd9a7"/>
<stop offset="0.34" stop-color="#edecc8"/>
<stop offset="1" stop-color="#ffffdc"/>
</linearGradient>
<linearGradient id="linear-gradient-2" x1="362.18" y1="531.34" x2="362.18" y2="43.96" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#fff" stop-opacity="0"/>
<stop offset="0.5" stop-color="#fff" stop-opacity="0.3"/>
<stop offset="1" stop-color="#fff" stop-opacity="0"/>
</linearGradient>
<linearGradient id="linear-gradient-3" x1="611.97" y1="531.34" x2="611.97" y2="43.96" xlink:href="#linear-gradient-2"/>
</defs>
<path id="wall" class="cls-1" d="M0,0V576l1024,1V1ZM889.5,509a23.1,23.1,0,0,1-23,23l-709-1a23.1,23.1,0,0,1-23-23V68a23.1,23.1,0,0,1,23-23l709,1a23.1,23.1,0,0,1,23,23Z"/>
<path id="glass" class="cls-2" d="M877.5,533l-731-1a12,12,0,0,1-12-12V57.9a12,12,0,0,1,12-12l731,1a12,12,0,0,1,12,12V521A12,12,0,0,1,877.5,533Z"/>
<g id="glass_shine" data-name="glass shine">
<polygon class="cls-3" points="557.4 531.3 437 531.3 167 44 287.4 44 557.4 531.3"/>
<polygon class="cls-4" points="807.1 531.3 686.8 531.3 416.8 44 537.1 44 807.1 531.3"/>
</g>
<polygon id="shadow" class="cls-5" points="916 577 160.9 576 134.9 513.2 890 514.2 916 577"/>
<g id="Window">
<path id="Window_shadow" data-name="Window shadow" class="cls-6" d="M868.5,44.9l-712-1a23.1,23.1,0,0,0-23,23V512a23.1,23.1,0,0,0,23,23l712,1a23.1,23.1,0,0,0,23-23V68A23.1,23.1,0,0,0,868.5,44.9Zm2.8,446.2a23.1,23.1,0,0,1-23,23l-672.5-1a23.1,23.1,0,0,1-23-23V85.8a23.1,23.1,0,0,1,23-23l672.5,1a23.1,23.1,0,0,1,23,23Z"/>
<path id="Window_border" data-name="Window border" class="cls-7" d="M866.5,45.9l-709-1a23.1,23.1,0,0,0-23,23V508a23.1,23.1,0,0,0,23,23l709,1a23.1,23.1,0,0,0,23-23V69A23.1,23.1,0,0,0,866.5,45.9Zm4.8,445.2a23.1,23.1,0,0,1-23,23l-672.5-1a23.1,23.1,0,0,1-23-23V85.8a23.1,23.1,0,0,1,23-23l672.5,1a23.1,23.1,0,0,1,23,23Z"/>
<path id="Window_highlight" data-name="Window highlight" class="cls-8" d="M851.5,59.9l-679-1a23.1,23.1,0,0,0-23,23V494a23.1,23.1,0,0,0,23,23l679,1a23.1,23.1,0,0,0,23-23V83A23.1,23.1,0,0,0,851.5,59.9Zm19.8,431.2a23.1,23.1,0,0,1-23,23l-672.5-1a23.1,23.1,0,0,1-23-23V85.8a23.1,23.1,0,0,1,23-23l672.5,1a23.1,23.1,0,0,1,23,23Z"/>
</g>
</svg>
</div>
</article>
<article id="container3">
<div id="rain"></div>
</article>
<article id="container4">
<div id="conveyor">
<svg id="conveyorBox" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 158 142.1">
<defs>
<style>
.box-1 {
fill: #bf0000;
}
.box-2 {
fill: #c00;
}
.box-3 {
fill: #fff200;
opacity: 0.8;
}
.box-4 {
opacity: 0.2;
}
</style>
</defs>
<rect id="body" class="box-1" x="10" y="4.1" width="138" height="137.99" rx="4.8" ry="4.8"/>
<rect id="lid" class="box-2" width="158" height="37.99" rx="4.6" ry="4.6"/>
<rect id="ribbon" class="box-3" x="67" width="24" height="142"/>
<rect id="shadow" class="box-4" x="10" y="38" width="138" height="17.5"/>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1024 576">
<defs>
<style>
.conveyor-1 {
opacity: 0.1;
}
.conveyor-2, .conveyor-5 {
stroke: #000;
}
.conveyor-2, .conveyor-4, .conveyor-5 {
stroke-miterlimit: 10;
stroke-width: 3px;
}
.conveyor-2 {
fill: url(#conveyor-gradient);
}
.conveyor-3 {
fill: #595959;
}
.conveyor-4 {
fill: #727272;
stroke: #333;
}
.conveyor-5 {
fill: url(#conveyor-radial-gradient);
}
</style>
<linearGradient id="conveyor-gradient" x1="97" y1="43.5" x2="97" y2="1.5" gradientUnits="userSpaceOnUse">
<stop offset="0.15" stop-color="#a6a6a6"/>
<stop offset="0.5" stop-color="#a6a6a6"/>
<stop offset="0.5" stop-color="#b3b3b3"/>
<stop offset="0.75" stop-color="#b3b3b3"/>
<stop offset="0.75" stop-color="#d9d9d9"/>
</linearGradient>
<radialGradient id="conveyor-radial-gradient" cx="930.59" cy="473.5" r="12.07" gradientUnits="userSpaceOnUse">
<stop offset="0.25" stop-color="lime"/>
<stop offset="0.28" stop-color="#00be00"/>
<stop offset="1" stop-color="#006400"/>
</radialGradient>
<symbol id="beltSection" data-name="beltSection" viewBox="0 0 194 62">
<rect id="shadow" class="conveyor-1" x="1" y="43" width="191" height="19"/>
<rect id="belt_section" data-name="belt section" class="conveyor-2" x="1.5" y="1.5" width="191" height="42"/>
</symbol>
</defs>
<g id="conveyorBelt">
<rect id="Belt_Base" data-name="Belt Base" class="conveyor-3" y="482" width="1024" height="94"/>
<rect class="conveyor-4" x="120.5" y="494.5" width="34" height="82"/>
<g id="Belt">
<use id="beltSection-3" data-name="beltSection" width="194" height="62" transform="translate(-51 451)" xlink:href="#beltSection"/>
<use width="194" height="62" transform="translate(140 451)" xlink:href="#beltSection"/>
<use width="194" height="62" transform="translate(331 451)" xlink:href="#beltSection"/>
<use width="194" height="62" transform="translate(522 451)" xlink:href="#beltSection"/>
<use width="194" height="62" transform="translate(713.2 451)" xlink:href="#beltSection"/>
<use width="194" height="62" transform="translate(904 451)" xlink:href="#beltSection"/>
</g>
<rect class="conveyor-4" x="869.5" y="494.5" width="34" height="82"/>
<rect class="conveyor-4" x="494.5" y="494.5" width="34" height="82"/>
<circle class="conveyor-5" cx="930.6" cy="473.5" r="12.1"/>
</g>
</svg>
</div>
</article>
</main>
body {
display: flex;
justify-content: center;
margin: 0;
padding: 0;
}
main {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
align-items: center;
width: 100vw;
position: relative;
& > article {
width: 100%;
border: 2px solid black;
box-sizing: border-box;
/* Mandatory */
position: relative;
overflow: hidden;
/* 16:9 aspect ratio */
& > div {
width: 100%;
padding-top: 56.25%;
}
visibility: hidden;
}
@media (min-width:640px) {
& > article {
width: 50%;
margin-bottom: 0;
}
}
}
#container1 {
/* Cosmetic */
background: hsl(187, 20%, 85%);
background: linear-gradient(hsl(187, 20%, 85%), hsl(187, 20%, 70%));
#clouds {
position: relative;
& > * {
position: absolute;
left: 0;
top: 0;
width: 30%;
height: 20%;
background-size: contain;
background-repeat: no-repeat;
}
.cloud1 {
background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/cloud1.png');
}
.cloud2 {
background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/cloud2.png');
}
.cloud3 {
background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/cloud3.png');
}
.d1 {
top: 20%;
}
.d2 {
top: 33%;
}
.d3 {
top: 42%;
}
.d4 {
top: 50%;
}
}
}
#container2 {
svg {
height: 100%;
position: absolute;
width: 100%;
bottom: 0;
left: 0;
}
.clouds {
fill: #fff;
top: 20%;
}
#cloud1 {
width: 9.92%;
height: 10.68%;
}
#cloud2 {
width: 9%;
height: 8%;
}
#cloud3 {
width: 11.11%;
height: 8.96%;
}
#grass {
height: 25.74%;
}
.hills {
bottom: 25%;
}
#hill1 {
width: 36.35%;
height: 35.59%;
}
#hill2 {
width: 27.35%;
height: 35.6%;
}
#hill3 {
width: 22.38%;
height: 30.92%;
}
#hill4 {
width: 32.04%;
height: 43.26%;
}
#hill5 {
width: 31.55%;
height: 26.86%;
}
#hill6 {
width: 36.35%;
height: 35.59%;
}
#powerline {
width: 5.625%;
height: 87%;
}
}
#container3 {
background: hsl(234, 100%, 5);
#rain {
transform: rotate(30deg) scale(1.2, 2);
}
.drop {
border-radius: 100%;
background: #084584;
background: #fff;
width: 1%;
padding-top: 2%;
position: absolute;
left: 0;
top: 0;
}
}
#container4 {
svg {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
#conveyorBox {
width: 15.43%;
height: 24.66%;
bottom: 20%;
top: auto;
}
}
console.clear();
/* *************************************** */
/* ************************************** */
var floaters = function(elements, container) {
// If no container given, use window size?
var stage = getSize(container);
//
var plates = {};
var depth = Math.abs(elements.depth) || 2;
var dur = stage.width / 4 / (Math.abs(elements.speed) || 1);
// Get all elements in the background
if(elements.bg) {
plates.bg = createTweens(elements.bg.target, 1/depth, elements.bg.ordered);
}
if(elements.mg) {
plates.mg = createTweens(elements.mg.target, 1, elements.mg.ordered);
}
if(elements.fg) {
plates.fg = createTweens(elements.fg.target, depth, elements.fg.ordered);
}
window.addEventListener('resize', _throttle(resize, 50));
/* ******************* */
/* Main Tweening setup */
/* ******************* */
function createTweens(targets, depth, ordered) {
var array = selectAllElements(targets);
var ttl = array.length;
var result = [];
for(var i = 0; i < ttl; i++) {
if(ordered) {
// Spread the elements along the length of the tween
result.push(createTween(array[i], depth, (i+1) * (1 / ttl)));
} else {
result.push(createTween(array[i], depth));
}
}
return result;
}
function createTween(el, depth, progress) {
var t;
if(elements.vertical) {
t = TweenMax.fromTo(el, dur,
{
y: -getSize(el).height,
rotation: 0
},
{
y: stage.height,
rotation: 0.1, // To force 3D transforms
ease: Linear.easeNone,
onComplete:function() {
t.restart();
},
onReverseComplete:function() {
t.seek(t.totalDuration(), true);
}
}
);
} else {
t = TweenMax.fromTo(el, dur,
{
x: -getSize(el).width,
rotation: 0
},
{
x: stage.width,
rotation: 0.1, // To force 3D transforms
ease: Linear.easeNone,
onComplete:function() {
t.restart();
},
onReverseComplete:function() {
t.seek(t.totalDuration(), true);
}
}
);
}
if(progress) {
// Only supress events if playing the animation backwards
t.progress(progress, elements.reversed);
} else {
t.progress(Math.random());
}
// Adjust the speed according to the distance
if(elements.depth) {
t.timeScale(depth);
}
// Play backwards if reversed
if(elements.reversed) {
t.reverse()
}
// t.pause();
return t;
}
function updateTweens(plate, depth) {
var temp = [];
for(var i = 0; i < plate.length; i++) {
var tween = plate[i];
// Record the tween's progress
var progress = tween.progress();
// Reset and recreate the tween
tween.pause(0);
temp.push(createTween(tween.target, depth, progress));
}
return temp;
}
/* **************** */
/* Helper functions */
/* **************** */
function getSize(target) {
var trg = (
document.getElementById(target.id)
||
document.getElementsByClassName(target.className)[0]
||
document.getElementsByTagName(target)[0]
||
document.querySelector(target)).getBoundingClientRect();
return {
width: Math.round(trg.width),
height: Math.round(trg.height)
};
}
function addArrays(array1, array2) {
array1 = array2.reduce( function(collection, item) {
collection.push(item);
return collection;
}, array1);
return array1;
}
function resize() {
// Update the stage's width
stage = getSize(container);
if(elements.bg) {
plates.bg = updateTweens(plates.bg, 1/depth)
}
if(elements.mg) {
plates.mg = updateTweens(plates.mg, 1)
}
if(elements.fg) {
plates.fg = updateTweens(plates.fg, depth)
}
}
/* By the mighty grace of OSUBlake */
/* http://codepen.io/osublake/ */
function selectAllElements(selector, context) {
var nodeList = (context || document).querySelectorAll(selector);
var i = nodeList.length;
var elements = new Array(i);
while (i--) { elements[i] = nodeList[i]; }
return elements;
}
/* 'Borrowed' from underscore */
function _now() {
return Date.now() || function() {
return new Date().getTime();
}
}
/* 'Borrowed' from underscore */
function _throttle(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
if (!options) options = {};
var later = function() {
previous = options.leading === false ? 0 : _now();
timeout = null;
result = func.apply(context, args);
if (!timeout) context = args = null;
};
return function() {
var now = _now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0 || remaining > wait) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
previous = now;
result = func.apply(context, args);
if (!timeout) context = args = null;
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
};
return plates;
};
/* *************************************** */
/* ************************************** */
// Wait for the DOM elements
window.onload = function() {
// All object keys are optional
var clouds = floaters({
bg: {
target:'.background', // {CSS selector} no default
ordered: true // {Boolean} defaults to false
},
mg:{
target:'.midground', // {CSS selector} no default
ordered: true // {Boolean} defaults to false
},
fg:{
target:'.foreground', // {CSS selector} no default
ordered: true // {Boolean} defaults to false
},
depth: 1.5, // {Number}, defaults to 2
speed: 0.5, // {Number}, defaults to 1
// reversed: true, // {Boolean} defaults to false
// vertical: true // {Boolean} defaults to false
}, '#container1');
var trainView = floaters({
bg:{
target:'.clouds',
},
mg:{
target:'.hills',
ordered: true
},
fg:{
target:'#powerline'
},
depth: 20,
speed: 15
}, '#container2');
// Make a bunch of raindrops because I am lazy
var dropsHolder = document.getElementById('rain');
for(var i = 0; i < 50; i++) {
var div = document.createElement('div');
div.className = 'drop';
// Space it somewhere along its parent
TweenMax.set(div, {
left: function() {
return Math.random() * 100 + '%';
}
});
// Give it some varied speed
if(i % 2 === 0) {
div.className += ' mediumRain';
} else if(i % 3 === 0) {
div.className += ' slowRain';
} else {
div.className += ' fastRain';
}
dropsHolder.appendChild(div);
}
var rain = floaters({
bg:{
target:'.slowRain'
},
mg:{
target:'.mediumRain'
},
fg:{
target:'.fastRain'
},
speed: 200,
depth: 1.2,
vertical: true
}, '#container3');
var conveyor = floaters({
mg: {
target:'#conveyorBox'
},
reversed: true,
speed: 30
}, '#container4');
// Once everything is ready, fade the assets in
TweenMax.to('article', 0.15, {autoAlpha:1, ease:Power4.easeIn});
}
Also see: Tab Triggers