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.
<nav class="navbar navbar-expand-md navbar-light bg-light fixed-top">
<a class="navbar-brand" href="#">START</a>
<button
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarsExampleDefault"
aria-controls="navbarsExampleDefault"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#one">Section 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#two">Section 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#three">Section 3</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#four">Section 4</a>
</li>
</ul>
</div>
</nav>
<main role="main" class="container-fluid">
<div class="row no-gutters">
<div class="col text-center">
<h1 class="py-5">SCROLL DOWN TO TRY ANIMATIONS</h1>
<img
src="https://drive.google.com/uc?export=view&id=1g2iw0lEBMYFyKjI9A1jN2wm0glHiXubt"
class="img-fluid"
alt="Responsive image"
/>
</div>
</div>
<section id="intro" class="section">
<div class="row no-gutters">
<div class="col">
<div>
The Neuron scales the steepest climbs and descends with complete
control thanks to its 130 - 140mm suspension, 29” wheels (in sizes
M-XL) and confidence-inspiring geometry.
</div>
</div>
</div>
</section>
<section id="one" class="section">
<div class="row no-gutters">
<div class="col">
<div class="rectangle"></div>
<div class="elem">
<div class="text-block">
<h2 class="mb-0">2021</h2>
<h5>Neuron CF SLX 9</h5>
</div>
<div class="blocks">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
</div>
</div>
</section>
<section id="two" class="section">
<div class="row no-gutters">
<div class="col">
<div class="elem">
<div>
<img
src="https://drive.google.com/uc?export=view&id=1wx3G8XcML7t9hTiE1ioUkLUiqUHkI_AJ"
class="img-fluid"
alt="Responsive image"
/>
</div>
</div>
</div>
</div>
</section>
<section id="three" class="section">
<div class="image"></div>
<div class="row no-gutters">
<div class="col">
<div class="elem">
<h2>GET OUT THERE</h2>
</div>
</div>
</div>
</section>
<section id="four" class="section">
<div class="image"></div>
<div class="row no-gutters">
<div class="col">
<div class="elem">
<h2>GO RIDE</h2>
</div>
</div>
</div>
</section>
</main>
body {
padding-top: 56px;
font-weight: 300;
letter-spacing: 0.03em;
background-color: #f7f7f7;
}
nav.navbar {
border-bottom: solid 1px #d6d6d6;
}
.navbar .navbar-brand {
font-weight: 500;
letter-spacing: .065em;
}
.navbar-nav .nav-link {
letter-spacing: .035em;
}
.navbar li.active a {
font-weight: 400;
}
main.container-fluid {
padding-left: 0;
padding-right: 0;
}
.spacer {
height: 40vh;
}
.rectangle {
position: absolute;
width: 97vw;
height: 30vw;
border-radius: 10px;
background: linear-gradient(45deg, #69b7bf 25%, #ffe664);
}
@media (min-width: 500px) {
.rectangle {
width: 80%;
}
}
.section > .row > .col {
height: 100vh;
display: flex;
justify-content: center;
align-content: center;
align-items: center;
}
#intro .col {
height: 50vh;
padding: 9vw 6vw;
font-size: 18px;
}
@media (min-width: 1000px) {
#intro .col {
padding: 18vw 12vw;
font-size: 2.7vw;
}
}
#one {
background-color: #212121;
}
#one .elem {
opacity: 0;
letter-spacing: 0.04em;
}
#one .text-block h2 {
font-size: 5vw;
letter-spacing: 0.2em;
font-weight: 300;
line-height: 1;
}
#one .text-block h5 {
font-size: 4vw;
line-height: 1;
}
#one .elem .blocks {
display: flex;
justify-content: space-between;
align-content: center;
align-items: center;
}
#one .elem .blocks > div {
height: 20px;
width: 20px;
margin: 2px;
border-radius: 2px;
background-color: #333;
}
#two {
height: auto;
overflow: hidden;
padding: 3vw 15vw 10vw;
background: linear-gradient(0deg, #69b7bf 25%, #ffe664);
}
#three, #four {
position: relative;
overflow: hidden;
}
#three .image, #four .image {
position: absolute;
top: 0;
bottom:0;
width: 100%;
}
#three .image {
background-image: url("https://drive.google.com/uc?export=view&id=10tzeBrvoR5OO3EK_Wcg-gRxbVO7xv6em");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
#four .image {
background-image: url("https://drive.google.com/uc?export=view&id=1SzCTDu5_eAF569lFHtNyIlUCrdW2mOXu");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
// Add active class to current nav selected link
var a = document.querySelectorAll(".navbar li a");
for (var i = 0, length = a.length; i < length; i++) {
a[i].onclick = function() {
var b = document.querySelector(".navbar li.active");
if (b) b.classList.remove("active");
this.parentNode.classList.add('active');
};
}
// Color palette variables
let dark = '#252525';
let mid = '#888';
let light = 'rgba(255, 255, 255, 0.4)';
// Add scrollmagic controller
let controller = new ScrollMagic.Controller();
//------------------
//TIMELINE 1
//------------------
// Add timeline
let tl1 = anime.timeline({autoplay: false});
// Add animations
let s1a1 = {
targets: '#one .elem',
opacity: 1,
translateX: {
value: [250, 0],
duration: 800
},
rotate: {
value: [90, 0],
duration: 1200,
easing: 'easeInOutSine'
},
scale: {
value: [2, 1.5],
duration: 1100,
delay: 800,
easing: 'easeInOutQuart'
},
color: [light, dark],
duration: 800,
delay: 0,
easing: 'easeInOutSine'
};
let s1a2 = {
targets: '#one .elem .blocks > div',
backgroundColor: [light, dark],
borderRadius: function(el) { return anime.random(2, 10); },
delay: function(el) { return anime.random(0, 800); }
};
let s1a3 = {
targets: '#one .rectangle',
opacity: [0,1],
translateX: {
value: ['-100vw', '0vw'],
duration: 1500,
},
translateY: {
value: [-100, 0],
duration: 1500,
},
easing: 'easeInOutSine',
duration: 2000
};
// Add children
tl1.add(s1a3).add(s1a1, '-=1600').add(s1a2, '-=1300');
// Get section height
let oneHeight = document.getElementById("one").clientHeight;
console.log('oneHeight: ' + oneHeight);
//------------------
//SCENE 1
//------------------
//Add first scrollmagic scene
let scene1 = new ScrollMagic.Scene({
triggerElement: "#one",
triggerHook: 0.5,
reverse: false
})
// Add debug indicators
.addIndicators({
colorTrigger: "black",
colorStart: "blue",
colorEnd: "red",
indent: 10
})
// Trigger animation timeline
.on("enter", function (event) {
tl1.play();
})
.addTo(controller);
//------------------
//TIMELINE 2
//------------------
// Add timeline
let tl2 = anime.timeline({autoplay: false});
// Add animations
let s2a1 = {
targets: '#two .elem img',
opacity: [0.3,1],
scale: [4,1],
duration: 1000,
delay: 0,
easing: 'easeInOutSine'
};
let s2a2 = {
targets: '#two .elem img',
scale: 1,
duration: 2000,
};
// Add children
tl2.add(s2a1).add(s2a2);
// Get section height
let twoHeight = document.getElementById("two").clientHeight;
console.log('twoHeight: ' + twoHeight);
//------------------
//SCENE 2
//------------------
//Add second scrollmagic scene
let scene2 = new ScrollMagic.Scene({
triggerElement: "#two",
duration: 4500,
triggerHook: 0,
})
// Add debug indicators
.addIndicators({
colorTrigger: "black",
colorStart: "blue",
colorEnd: "red",
indent: 10
})
// Trigger animation timeline
//Use scroll position to play animation
.on("progress", function (event) {
tl2.seek(tl2.duration * event.progress);
})
.setPin('#two')
.addTo(controller);
//------------------
//TIMELINE 3
//------------------
// Add timeline
let tl3 = anime.timeline({autoplay: false});
// Add animations
let s3a1 = {
targets: '#three h2',
opacity: 1,
scale: [4,1.5],
duration: 1000,
delay: 0,
easing: 'easeInOutSine'
};
// Add children
tl3.add(s3a1);
//------------------
//TIMELINE 4
//------------------
// Add timeline
let tl4 = anime.timeline({autoplay: false});
// Add animations
let s3a2 = {
targets: '#three .image',
opacity: [0,.5],
translateX: {
value: ['-100%', '0%'],
duration: 1500,
},
duration: 1000,
delay: 0,
easing: 'easeInOutSine'
};
// Add children
tl4.add(s3a2);
//------------------
//SCENE 3
//------------------
//Add third scrollmagic scene
let scene3 = new ScrollMagic.Scene({
triggerElement: "#three",
duration: 2000,
triggerHook: 0
})
// Add debug indicators
.addIndicators({
colorTrigger: "black",
colorStart: "blue",
colorEnd: "red",
indent: 10
})
// Trigger animation timeline
//Use scroll position to play animation
.on("enter", function (event) {
tl3.play();
})
.on("progress", function (event) {
tl4.seek((tl4.duration * event.progress) * 3);
})
.setPin('#three')
.addTo(controller);
//------------------
//TIMELINE 5
//------------------
// Add timeline
let tl5 = anime.timeline({autoplay: false});
// Add animations
let s4a1 = {
targets: '#four h2',
opacity: 1,
scale: [1.5,3],
duration: 1000,
delay: 0,
easing: 'easeInOutSine'
};
// Add children
tl5.add(s4a1);
//------------------
//TIMELINE 6
//------------------
// Add timeline
let tl6 = anime.timeline({autoplay: false});
// Add animations
let s4a2 = {
targets: '#four .image',
opacity: [0,.5],
translateX: {
value: ['100%', '0%'],
duration: 1500,
},
duration: 1000,
delay: 0,
easing: 'easeInOutSine'
};
// Add children
tl6.add(s4a2);
//------------------
//SCENE 4
//------------------
//Add third scrollmagic scene
let scene4 = new ScrollMagic.Scene({
triggerElement: "#four",
duration: 2000,
triggerHook: 0
})
// Add debug indicators
.addIndicators({
colorTrigger: "black",
colorStart: "blue",
colorEnd: "red",
indent: 10
})
// Trigger animation timeline
//Use scroll position to play animation
.on("enter", function (event) {
tl5.play();
})
.on("progress", function (event) {
tl6.seek((tl6.duration * event.progress) * 3);
})
.setPin('#four')
.addTo(controller);
Also see: Tab Triggers