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="page">
<div class="wrapper">
<div class="bottom">
<!-- images got deleted :'( -->
<!-- <img src="http://i67.tinypic.com/2eo86ew.jpg" draggable="false"/> -->
</div>
<div class="middle">
<!-- <img src="http://i64.tinypic.com/15i68sz.jpg" draggable="false"/> -->
</div>
<div class="scroller scroller-middle">
<svg class="scroller__thumb" xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><polygon points="0 50 37 68 37 32 0 50" style="fill:#FFCCBC"/><polygon points="100 50 64 32 64 68 100 50" style="fill:#FFCCBC"/></svg>
</div>
<div class="top">
<img src="http://i64.tinypic.com/2ppni55.jpg" draggable="false"/>
</div>
<div class="scroller scroller-top">
<svg class="scroller__thumb" xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><polygon points="0 50 37 68 37 32 0 50" style="fill:#FFAB91"/><polygon points="100 50 64 32 64 68 100 50" style="fill:#FFAB91"/></svg>
</div>
</div>
</div>
/* You can remove this page div in your website */
#page{
width:100%;
height:100%;
position:absolute;
background:#eee;
}
/* Our normalize css */
*{
margin:0;
box-sizing: border-box;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Our wrapper */
.wrapper{
width: 690px;
height: 600px;
max-height:100vh;
position: absolute;
left:50%;
top:50%;
transform:translate3d(-50%,-50%,0);
overflow:hidden;
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}
/* Our image information */
.bottom,
.middle,
.top {
width:100%;
height:100%;
background-repeat:no-repeat;
background-color: white;
background-size: cover;
background-position: center;
position: absolute;
top:0;
left:0;
pointer-events:none;
overflow: hidden;
img {
height:100%;
}
}
.bottom{
background: #2196f3;
}
.middle {
background: #bbdefb;
}
.top{
background: #ffffff;
}
.top{
width:125px;
}
.scroller{
width: 50px;
height:50px;
position: absolute;
left:100px;
top:50%;
transform:translateY(-50%);
border-radius:50%;
background-color: #fff;
opacity:0.9;
transition: opacity 0.12s ease-in-out;
pointer-events:auto;
cursor: pointer;
box-shadow: 3.5px 0px 7px rgba(100, 100, 100, 0.2);
}
.scroller-middle{
margin-top:25px;
}
.scroller-top{
margin-top:-25px;
}
.scroller:hover{
opacity:1;
}
.scrolling{
pointer-events:none;
opacity:1;
// z-index: 1;
}
.scroller__thumb{
width:100%;
height:100%;
border-radius:50%;
padding: 7px;
}
.scroller:before,
.scroller:after{
content:" ";
display: block;
width: 7px;
height: 9999px;
position: absolute;
left: 50%;
margin-left: -3.5px;
z-index: 30;
transition:0.1s;
box-shadow: 3.5px 0px 7px rgba(100, 100, 100, 0.2);
}
.scroller:before{
top:49px;
}
.scroller:after{
bottom:49px;
}
/* If you want to cahnge the colors, make sure you change the fill in the svgs to match */
.scroller-middle>.scroller__thumb{
border: 5px solid #FFCCBC;
}
.scroller-middle:before,
.scroller-middle:after{
background: #FFCCBC;
}
.scroller-top>.scroller__thumb{
border: 5px solid #FFAB91;
}
.scroller-top:before,
.scroller-top:after{
background: #FFAB91;
}
// I hope this over-commenting helps. Let's do this!
// Let's use the 'active' variable to let us know when we're using it
let active = false;
// and define our dom elements to make it easier to read
let scrollerMiddle = document.querySelector('.scroller-middle');
let scrollerTop = document.querySelector('.scroller-top');
// First we'll have to set up our event listeners
// We want to watch for clicks on our scroller
scrollerMiddle.addEventListener('mousedown',function(){
active = "middle";
// Add our scrolling class so the scroller has full opacity while active
scrollerMiddle.classList.add('scrolling');
});
// We also want to watch the body for changes to the state,
// like moving around and releasing the click
// so let's set up our event listeners
document.body.addEventListener('mouseup',function(){
active = false;
scrollerMiddle.classList.remove('scrolling');
});
document.body.addEventListener('mouseleave',function(){
active = false;
scrollerMiddle.classList.remove('scrolling');
});
// We'll have to do the same for our top scroller
scrollerTop.addEventListener('mousedown',function(){
active = "top";
scrollerTop.classList.add('scrolling');
});
document.body.addEventListener('mouseup',function(){
active = false;
scrollerTop.classList.remove('scrolling');
});
document.body.addEventListener('mouseleave',function(){
active = false;
scrollerTop.classList.remove('scrolling');
});
// Let's figure out where their mouse is at
document.body.addEventListener('mousemove',function(e){
if (!active) return;
// Their mouse is here...
let x = e.pageX;
// but we want it relative to our wrapper
x -= document.querySelector('.wrapper').getBoundingClientRect().left;
// Okay let's change our state
scrollIt(x);
});
// Let's use this function
function scrollIt(x){
// Calculate our transform
let transform = Math.max(0,(Math.min(x,document.querySelector('.wrapper').offsetWidth)));
// we show all our bottom image but how much of our middle and top,
// that'll depend on what we're dragging
// if we're dragging the middle slider
if (active==="middle"){
document.querySelector('.middle').style.width = transform+"px";
scrollerMiddle.style.left = transform-25+"px";
// if we're using scroller-middle, middle must always be to the right of top
if (scrollerTop.getBoundingClientRect().left>scrollerMiddle.getBoundingClientRect().left-5){
document.querySelector('.top').style.width = transform-5+"px";
scrollerTop.style.left = transform-30+"px";
}
}
// if we're dragging the top slider
if (active==="top"){
document.querySelector('.top').style.width = transform+"px";
scrollerTop.style.left = transform-25+"px";
// if we're using scroller-top, top must always be to the left
if (scrollerTop.getBoundingClientRect().left>scrollerMiddle.getBoundingClientRect().left-5){
document.querySelector('.middle').style.width = transform+5+"px";
scrollerMiddle.style.left = transform-20+"px";
}
}
}
// Let's set our opening state based off the width,
// we want to show a bit of both images so the user can see what's going on
active = "middle";
scrollIt(460);
active = "top";
scrollIt(230);
active = false;
// And finally let's repeat the process for touch events
// first our middle scroller...
scrollerMiddle.addEventListener('touchstart',function(){
active = "middle";
scrollerMiddle.classList.add('scrolling');
});
document.body.addEventListener('touchend',function(){
active = false;
scrollerMiddle.classList.remove('scrolling');
});
document.body.addEventListener('touchcancel',function(){
active = false;
scrollerMiddle.classList.remove('scrolling');
});
// then scroller top, our second scroller
scrollerTop.addEventListener('touchstart',function(){
active = "top";
scrollerTop.classList.add('scrolling');
});
document.body.addEventListener('touchend',function(){
active = false;
scrollerTop.classList.remove('scrolling');
});
document.body.addEventListener('touchcancel',function(){
active = false;
scrollerTop.classList.remove('scrolling');
});
document.querySelector('.wrapper').addEventListener('touchmove',function(e){
if (!active) return;
e.preventDefault();
let x = e.touches[0].pageX;
x -= document.querySelector('.wrapper').getBoundingClientRect().left;
scrollIt(x);
});
Also see: Tab Triggers