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 class="page">
<div class="container">
<div class="carousel">
<ul class="carousel-pagination">
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
<li class="carousel-bullet"></li>
</ul>
<div class="carousel-container">
<p class="carouselPara">
This book is here to help you get your job done. In general, if this book includes code examples, you may use the code in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of
the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this
book and quoting example code does not require permission. Incorporating a significant amount of ex‐ ample code from this book into your product’s documentation does require permission. We appreciate, but do not require, attribution. An attribution
usually includes the title, author, publisher, and ISBN. For example: “Developing Backbone.js Applications by Adnan Osmani (O’Reilly). Copyright 2013 Addy Osmani, 978-1-449-32825-2.” If you feel your use of code examples falls outside fair use
or the permission given above, feel free to contact us at [email protected]. Safari® Books Online Safari Books Online (www.safaribooksonline.com) is an on-demand digital library that delivers expert content in both book and video form
from the world’s leading authors in technology and business. Technology professionals, software developers, web designers, and business and crea‐ tive professionals use Safari Books Online as their primary resource for research, prob‐ lem solving,
learning, and certification training. Safari Books Online offers a range of product mixes and pricing programs for organi‐ zations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication
manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Pro‐ fessional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan
Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online. </p>
</div>
</div>
</div>
</div>
body {
background: #FFF;
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
overflow-y: scroll;
overflow-x: hidden;
min-height: 600px;
}
.page {
margin-top: 50px;
width: 700px;
height: 300px;
}
.container {
width: 700px;
height: 100%;
margin: 0 auto;
box-shadow: 0 16px 18px -10px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0 16px 18px -10px rgba(0, 0, 0, 0.5);
-webkit-box-shadow: 0 16px 18px -10px rgba(0, 0, 0, 0.5);
-o-box-shadow: 0 16px 18px -10px rgba(0, 0, 0, 0.5);
border-radius: 0px 0px 10px 10px;
}
.carousel {
position: relative;
overflow: hidden;
width: 700px;
}
.carousel-pagination {
list-style: none;
position: absolute;
left: 0;
right: 0;
width: 700px;
height: 25px;
padding: 10px 0px 0px 0px;
margin: 0 auto;
text-align: center;
z-index: 10;
background-color: #F6F6F6;
}
.carousel-bullet {
display: inline-flex;
width: 10px;
height: 10px;
background-color: #B7B7B7;
cursor: pointer;
border-radius: 50%;
opacity: 0.5;
/* transition-property: transform, opacity, background-color; */
/* transition-duration: 0.3s; */
}
/* .carousel-bullet:hover {
-webkit-transform: scale(1.1);
transform: scale(1.1);
} */
/* .carousel-bullet.active-bullet, .carousel-bullet.active-bullet:hover {
opacity: 1;
-webkit-transform: scale(1.1);
transform: scale(1.1);
background-color: #324892;
cursor: default;
} */
.carousel-container {
background-color: #CCC;
margin-top: 50px;
width: 700px;
height: 300px;
/* transition: transform 0.3s cubic-bezier(.694, .0482, .335, 1); */
overflow-y: hidden;
overflow-x: scroll;
}
p {
padding: 10px;
width: 200%;
}
var container = document.querySelector(".carousel-container");
var bulletElements = document.querySelectorAll(".carousel-bullet");
var scrollArea = container.scrollWidth - container.offsetWidth;
var length = bulletElements.length;
var bullets = [];
var requestId = null;
// Prevent Chrome from rasterizing at scale of 1
// https://greensock.com/will-change
TweenLite.set(bulletElements, {
force3D: true
});
for (var i = 0; i < length; i++) {
var bullet = createBullet(bulletElements[i], i);
bullets.push(bullet);
}
container.addEventListener("scroll", requestScrollUpdate);
updateScroll();
// Throttle scroll events to animation frames
function requestScrollUpdate() {
if (!requestId) {
requestId = requestAnimationFrame(updateScroll);
}
}
function updateScroll() {
var ratio = container.scrollLeft / scrollArea;
var cursor = Math.floor((length - 1) * ratio);
for (var i = 0; i < length; i++) {
bullets[i].updateProgress(cursor);
}
requestId = null;
}
function createBullet(element, index) {
var animation = new TimelineMax({ paused: true })
.to(element, 1, { scale: 2, backgroundColor: "pink" })
.to(element, 1, { scale: 3, backgroundColor: "red" })
var bullet = {
element: element,
index: index,
animation: animation,
updateProgress: updateProgress
};
function updateProgress(cursor) {
// Use a small progress value here instead of 0
// to work around will-change issue in Chrome
var progress = 0.0001;
if (cursor === index) {
progress = 1;
} else if (cursor === index - 1 || cursor === index + 1) {
progress = 0.5;
}
if (animation.progress() !== progress) {
TweenLite.to(animation, 0.25, { progress: progress });
}
}
return bullet;
}
Also see: Tab Triggers