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.
<div id="container">
<div id="aaa">
<div>=======================================</div>
<p>Just here to fill space a bit</p>
<div>=======================================</div>
<div>=======================================</div>
<div>=======================================</div>
<div>=======================================</div>
</div>
<div id="first" style="width:100%;" class="added_class_wondering_if_one_had_to_be_here">
<div>=======================================</div>
<div>=======================================</div>
<div>=======================================</div>
<div>=======================================</div>
<div>=======================================</div>
</div>
<div id="second">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In placerat dolor et molestie elementum. Pellentesque et mauris malesuada, gravida arcu nec, dapibus mi. Nunc placerat sapien eu vulputate tempus. Vivamus nisi ex, efficitur nec fermentum a, placerat eu sapien. Quisque viverra mauris vitae bibendum aliquet. Phasellus mattis magna vitae dolor consequat, vel vehicula neque commodo. Donec in ultrices neque. Etiam a lacus ligula. Quisque eleifend sapien mi, a placerat lectus vulputate quis. Cras id tempus mauris.
</p>
<p>
Nulla convallis non lorem sed fringilla. Vestibulum sodales, erat id convallis egestas, felis lectus tempus ipsum, non laoreet augue mi egestas ipsum. Sed ultricies dui ac nisi dignissim varius. Fusce bibendum rhoncus diam. Maecenas molestie nisl non lacus iaculis, quis tristique mi venenatis. Donec mi dolor, fermentum in hendrerit quis, semper ut purus. Pellentesque accumsan ex non sem semper, porta tempus arcu rutrum. Pellentesque libero enim, lobortis et arcu a, imperdiet cursus felis. Proin id nisl et sapien vulputate cursus. Suspendisse consequat vehicula dui eget venenatis. Quisque condimentum neque non nulla aliquam cursus. Cras tortor lectus, venenatis id elit quis, bibendum iaculis tortor. Nullam tempus varius orci, nec posuere eros bibendum quis. Duis gravida mauris et leo efficitur facilisis vitae a turpis.
</p>
<p>
Suspendisse dapibus est quam, a interdum massa cursus et. Phasellus et dignissim purus. Suspendisse turpis dolor, sagittis eu dapibus non, dapibus ut enim. In venenatis, enim quis scelerisque fermentum, urna erat semper nunc, vitae imperdiet nunc ex eget mauris. Sed rutrum diam id lacinia tempus. Suspendisse consequat varius ipsum quis tristique. Pellentesque sed augue sem. Fusce tempus pretium rhoncus. Phasellus non aliquet dui. Etiam ante tortor, tincidunt eu vulputate nec, euismod non massa. Suspendisse potenti.
</p>
<p>
Ut eleifend elit dictum dui efficitur, non scelerisque lectus egestas. Etiam lacinia pellentesque erat sed placerat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec felis neque, tempor in velit vel, iaculis facilisis diam. Pellentesque eget dolor orci. Duis dolor nisl, imperdiet a leo sed, gravida hendrerit tellus. Donec finibus libero eget rutrum pellentesque.
</p>
<p>
Mauris sed mauris facilisis, sollicitudin lorem ut, tempor massa. Sed nec mi id ex facilisis iaculis in non magna. Integer nibh est, elementum vel augue tincidunt, euismod facilisis nulla. Nulla mattis nec elit id tincidunt. Nullam consectetur eros non tempus blandit. Suspendisse massa ipsum, vestibulum sed feugiat sit amet, porttitor non lorem. Nulla bibendum erat sed leo ultrices convallis. Aenean nec ornare sapien. Nulla elementum posuere eros, vel interdum risus aliquam ut.
</p>
</div>
<div id="bottom_bottom">THIS IS THE ENDTRIGGER</div>
</div>
#container {
width:960px;
margin:auto;
}
#aaa {
width: 50%;
background:black;
margin:auto;
color:white;
padding:10px;
}
#first {
width: 100%;
background:grey;
padding:10px;
margin:auto;
display:static;
}
#first.active {
position: fixed;
top: 0;
left: 0;
}
.THIRD {
z-index:12000;
position:fixed;
width:100%;
}
#second {
width:20%;
background:darkblue;
color:white;
margin:auto;
padding:10px;
}
#bottom_bottom {
text-align:center;
background:red;
color:white;
padding:10px;
margin:0px;
}
gsap.registerPlugin(Flip, ScrollTrigger);
const first = document.querySelector("#first"),
second = document.querySelector("#second");
const trigger = ScrollTrigger.create({
trigger: first,
start: "top top",
end: "+=1", // we don't need anything long - all we care about is the initial trigger point since we're only using onEnter and onLeaveBack
markers: true,
onEnter: () => setState(true, true),
onLeaveBack: () => setState(false, true)
});
function setState(active, flip) {
const state = Flip.getState(first); // record the state
if (active) {
first.classList.add("active");
second.style.marginTop = first.offsetHeight + "px"; // push "#second" down by the height of the first because it gets taken out of the document flow with position: fixed
} else {
first.classList.remove("active");
second.style.marginTop = "0px";
}
if (flip) { // flip if we need to
Flip.from(state, {duration: 0.5});
}
}
// to make it responsive, we've gotta revert the state during ScrollTrigger.refresh() so that things are measured properly:
ScrollTrigger.addEventListener("refreshInit", () => setState(false, false));
ScrollTrigger.addEventListener("refresh", () => {
if (trigger.progress !== 0) { // if the user has scrolled PAST the trigger point, set the state accordingly.
setState(true, false);
}
});
Also see: Tab Triggers