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="navigation"><p>Hidden navigation for users that have trenched deep into your page!</p></div>
<div id="percentageCounter"><h1>0%</h1></div>
<div class="container">
<a href="https://github.com/ellenbrook/jQuery-scroll-distance-detection/" target="blank">This script has been updated. View the new (easy to use version) on Github!</a>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum vitae magna ut nulla lobortis iaculis. Maecenas eleifend nibh vehicula dolor interdum auctor. Nullam ut mi a dolor luctus pulvinar in quis nunc. Mauris molestie eget odio eget porttitor. Etiam suscipit ante sapien, non iaculis lacus vulputate non. Nulla vulputate lectus vel leo pulvinar, lobortis rutrum felis porta. Cras egestas, odio ac venenatis tincidunt, dui erat congue ligula, at congue nulla urna ac tortor. Ut in dolor varius, malesuada erat in, semper nisl. Cras euismod arcu sem, ac consectetur sapien rutrum quis. Vestibulum sed feugiat nulla. Duis lacinia ac mauris dictum pellentesque. Vestibulum ut dictum sem. Sed volutpat ornare nisi, vitae faucibus diam auctor id. Nam et euismod lectus.</p>
<p>In porttitor, velit id varius volutpat, purus purus ornare urna, in cursus mauris nibh vitae nisl. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec nibh neque, scelerisque a congue a, dictum eget mi. Donec iaculis mauris in porta eleifend. Nam eu nisi velit. Etiam a semper massa. Praesent consequat sapien facilisis tellus auctor, sit amet tincidunt augue faucibus. Aliquam adipiscing elit a congue malesuada. Sed justo urna, vehicula a velit sed, sollicitudin cursus nunc. In auctor sapien nunc, non aliquam nisi euismod a. Maecenas ut est fringilla massa laoreet ullamcorper at eu mauris. Praesent quis porttitor justo.</p>
<p>Cras mattis nibh nec justo tempor, id rhoncus magna sollicitudin. Cras iaculis dolor sit amet fermentum semper. Fusce eget pellentesque turpis. Cras placerat urna at lacus placerat, sit amet hendrerit magna aliquet. Vestibulum lobortis lectus et nibh imperdiet ornare. Sed quis purus hendrerit, sodales lectus quis, auctor sem. Donec felis sapien, tincidunt eget ullamcorper ac, scelerisque at ligula. Curabitur cursus placerat vulputate. Maecenas laoreet est nunc, sit amet eleifend libero suscipit in. Duis nunc urna, porttitor a elit at, iaculis tincidunt elit. Sed quis consectetur mauris. Nam ut semper dui.</p>
<p>Pellentesque porttitor tortor nec tortor ullamcorper, nec scelerisque mi condimentum. Morbi cursus molestie euismod. Sed ullamcorper massa rutrum arcu auctor, eu posuere nunc interdum. Mauris ac est tellus. Nullam quis odio leo. Aenean consequat, felis in tristique iaculis, neque erat semper risus, eu commodo orci nisi quis sapien. Nullam quis elementum est. Vestibulum malesuada blandit turpis, ut imperdiet justo porttitor ac. Nullam in cursus magna. Donec ultricies ante eget massa convallis, a elementum orci tincidunt. Quisque id vulputate nunc. Pellentesque ut dictum turpis, non gravida libero.</p>
<p>Proin molestie, urna non dapibus blandit, metus magna semper nisl, id tincidunt enim urna nec nulla. Quisque in magna et ante pharetra hendrerit placerat ac urna. Sed viverra turpis in sapien pellentesque, vel tincidunt sapien volutpat. Curabitur non nulla ac augue varius fringilla et sed augue. Phasellus quis consectetur urna. Donec molestie dui et tortor blandit, vel faucibus lacus consequat. Donec nulla diam, iaculis sed egestas ac, posuere vitae dui. Donec at cursus neque, non vestibulum enim. Aliquam augue nisi, eleifend sit amet dolor sit amet, consequat posuere orci. Cras nibh tellus, ornare at libero ac, consequat porta sapien. Aliquam ut mauris quis urna scelerisque luctus in ac enim. Nam nibh libero, mollis volutpat suscipit ac, viverra vel odio. Aliquam erat volutpat. Aenean adipiscing, nulla et ultrices commodo, lectus velit sagittis tellus, eget congue augue sapien at felis. Cras nec egestas sapien. Cras dapibus leo sed dolor laoreet, at ornare felis pretium.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum vitae magna ut nulla lobortis iaculis. Maecenas eleifend nibh vehicula dolor interdum auctor. Nullam ut mi a dolor luctus pulvinar in quis nunc. Mauris molestie eget odio eget porttitor. Etiam suscipit ante sapien, non iaculis lacus vulputate non. Nulla vulputate lectus vel leo pulvinar, lobortis rutrum felis porta. Cras egestas, odio ac venenatis tincidunt, dui erat congue ligula, at congue nulla urna ac tortor. Ut in dolor varius, malesuada erat in, semper nisl. Cras euismod arcu sem, ac consectetur sapien rutrum quis. Vestibulum sed feugiat nulla. Duis lacinia ac mauris dictum pellentesque. Vestibulum ut dictum sem. Sed volutpat ornare nisi, vitae faucibus diam auctor id. Nam et euismod lectus.</p>
<p>In porttitor, velit id varius volutpat, purus purus ornare urna, in cursus mauris nibh vitae nisl. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec nibh neque, scelerisque a congue a, dictum eget mi. Donec iaculis mauris in porta eleifend. Nam eu nisi velit. Etiam a semper massa. Praesent consequat sapien facilisis tellus auctor, sit amet tincidunt augue faucibus. Aliquam adipiscing elit a congue malesuada. Sed justo urna, vehicula a velit sed, sollicitudin cursus nunc. In auctor sapien nunc, non aliquam nisi euismod a. Maecenas ut est fringilla massa laoreet ullamcorper at eu mauris. Praesent quis porttitor justo.</p>
<p>Cras mattis nibh nec justo tempor, id rhoncus magna sollicitudin. Cras iaculis dolor sit amet fermentum semper. Fusce eget pellentesque turpis. Cras placerat urna at lacus placerat, sit amet hendrerit magna aliquet. Vestibulum lobortis lectus et nibh imperdiet ornare. Sed quis purus hendrerit, sodales lectus quis, auctor sem. Donec felis sapien, tincidunt eget ullamcorper ac, scelerisque at ligula. Curabitur cursus placerat vulputate. Maecenas laoreet est nunc, sit amet eleifend libero suscipit in. Duis nunc urna, porttitor a elit at, iaculis tincidunt elit. Sed quis consectetur mauris. Nam ut semper dui.</p>
<p>Pellentesque porttitor tortor nec tortor ullamcorper, nec scelerisque mi condimentum. Morbi cursus molestie euismod. Sed ullamcorper massa rutrum arcu auctor, eu posuere nunc interdum. Mauris ac est tellus. Nullam quis odio leo. Aenean consequat, felis in tristique iaculis, neque erat semper risus, eu commodo orci nisi quis sapien. Nullam quis elementum est. Vestibulum malesuada blandit turpis, ut imperdiet justo porttitor ac. Nullam in cursus magna. Donec ultricies ante eget massa convallis, a elementum orci tincidunt. Quisque id vulputate nunc. Pellentesque ut dictum turpis, non gravida libero.</p>
<p>Proin molestie, urna non dapibus blandit, metus magna semper nisl, id tincidunt enim urna nec nulla. Quisque in magna et ante pharetra hendrerit placerat ac urna. Sed viverra turpis in sapien pellentesque, vel tincidunt sapien volutpat. Curabitur non nulla ac augue varius fringilla et sed augue. Phasellus quis consectetur urna. Donec molestie dui et tortor blandit, vel faucibus lacus consequat. Donec nulla diam, iaculis sed egestas ac, posuere vitae dui. Donec at cursus neque, non vestibulum enim. Aliquam augue nisi, eleifend sit amet dolor sit amet, consequat posuere orci. Cras nibh tellus, ornare at libero ac, consequat porta sapien. Aliquam ut mauris quis urna scelerisque luctus in ac enim. Nam nibh libero, mollis volutpat suscipit ac, viverra vel odio. Aliquam erat volutpat. Aenean adipiscing, nulla et ultrices commodo, lectus velit sagittis tellus, eget congue augue sapien at felis. Cras nec egestas sapien. Cras dapibus leo sed dolor laoreet, at ornare felis pretium.</p>
</div>
$counter: true; //false to hide percentage
#navigation {
position: fixed;
top: -66px;
left: 0; right: 0;
width: 100%;
height: 60px;
background-color: #006699;
box-shadow: 0px 3px 3px 0px rgba(21, 21, 21, 0.1);
/*
#
#Edit these to change CSS transition delay, speed, and type
#
*/
transition: top .25s ease .5s;
}
#navigation p {
text-align: center;
color: #fff;
}
.container {
text-align: center;
margin-bottom: 2em;
}
#percentageCounter {
@if $counter == true {
position: fixed;
} @else if $counter == false {
display: none;
}
bottom: 10px;
right: 10px;
}
h1 {
font-size: +2em;
}
.content {
width: 30%;
margin: 0 auto;
padding: 10px;
border: 1px solid #000;
background-color: #f5f5f5;
}
p {
margin-bottom: 1em;
}
* { font-family: 'Open Sans', sans-serif; }
@import url(https://fonts.googleapis.com/css?family=Open+Sans:300);
$(window).scroll(function(){
// Change this to target a different percentage
var targetPercentage = 70;
//Change this to set the height of your nav bar so it hides properly. If you have a box shadow you may have to adjust this number to be height + shadow distance
var navBarHeight = 66;
//Change this to the ID of the content you are trying to show.
var targetID = "#navigation";
//Window Math
var scrollTo = $(window).scrollTop(),
docHeight = $(document).height(),
windowHeight = $(window).height();
scrollPercent = (scrollTo / (docHeight-windowHeight)) * 100;
scrollPercent = scrollPercent.toFixed(1);
$('#percentageCounter h1').text(scrollPercent+"%");
if(scrollPercent > targetPercentage) {
$(targetID).css({ top: '0' });
}
if(scrollPercent < targetPercentage) {
$(targetID).css({ top: '-'+navBarHeight+'px' });
}
}).trigger('scroll');
Also see: Tab Triggers