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="container">
<!-- Panels -->
<div class="swipe">
<div class="panel" data-img="http://payload100.cargocollective.com/1/9/296422/4317770/1%20-%20Landscape%201_o.jpg"></div>
<div class="panel" data-img="http://payload100.cargocollective.com/1/9/296422/4317770/1%20-%20Landscape%208_o.jpg"></div>
<div class="panel" data-img="http://payload100.cargocollective.com/1/9/296422/4317770/1%20-%20Landscape%209_o.jpg"></div>
<div class="panel" data-img="http://payload100.cargocollective.com/1/9/296422/4317770/2-%20Arquitectura%205_o.jpg"></div>
<div class="panel" data-img="http://payload100.cargocollective.com/1/9/296422/4317770/3%20-%20Interiores%201_o.jpg"></div>
</div>
<!-- Info -->
<div class="info">
<div class="inner">
<h3>Simply swipe on any device!</h3>
<p>Use this buttons or your fingers. No matter what you do, no matter which device you choose, the picture will swipe and swipe again!</p>
</div>
<div class="buttons">
<button class="btn-prev" disabled>←</button>
<button class="btn-next">→</button>
</div>
</div>
</div>
<!--
==================
==================
Optional Content
==================
==================
<div class="optional">
<h3>Lorem ipsum dolor sit amet.</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Possimus asperiores natus minus ab sit. Ipsum iste, doloribus suscipit ducimus ea repudiandae consequatur soluta repellat saepe fuga, velit odit odio facilis, at sunt quis quo molestias quae. Ullam nisi, error facilis nobis maxime numquam quaerat, voluptatibus sit debitis ea quasi incidunt?</p>
</div>
-->
<!-- Google Font -->
<link href="https://fonts.googleapis.com/css?family=Roboto+Slab" rel="stylesheet">
/* Global */
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
html,
body,
.container {
width: 100%;
height: 100%;
max-height: 100%;
margin: 0;
padding: 0;
/* Font styles */
font-family: 'Roboto Slab', serif;
font-size: 1em;
line-height: 1.5em;
color: #607D8B;
letter-spacing: .01em;
}
.container {
position: relative;
}
/* Panels */
.swipe {
position: relative;
width: 100%;
height: 100%; /* "min-height" doesn't work on Firefox. */
background: #eee;
overflow-x: hidden;
}
.panel {
position: absolute;
width: 100%;
min-height: 100%;
top: 0;
left: 0;
padding: 20px;
}
.left {
left: -100%;
}
.right {
left: 100%;
}
/* Info */
.info {
position: absolute;
width: 80%;
max-width: 500px;
bottom: 20%;
right: 10%;
pointer-events: none;
}
.inner {
position: relative;
padding: 1.66em 3em;
background: #FFFFFF;
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
}
.info:before {
content: "";
position: absolute;
width: 65%;
height: 80%;
top: 0;
left: 0;
-webkit-transform: translate(-10px, -10px);
-ms-transform: translate(-10px, -10px);
-o-transform: translate(-10px, -10px);
transform: translate(-10px, -10px);
background: #E91E63;
background: #3F51B5;
}
.buttons {
position: absolute;
bottom: -50px;
right: 5%;
pointer-events: all;
}
.buttons button {
transition: ease .4s;
}
.btn-prev,
.btn-next {
width: 60px;
height: 60px;
margin-left: 10px;
border: none;
outline: none;
border-radius: 60px;
color: #FFFFFF;
background: -webkit-linear-gradient(top, #F5515F, #E91E63);
background: linear-gradient(to bottom, #F5515F, #E91E63);
box-shadow: 0px 3px 15px 2px rgba(245,81,95,.8);
cursor: pointer;
}
.buttons button:hover {
box-shadow: 0px 3px 30px 3px rgba(245,81,95,.8);
}
.buttons button:disabled {
box-shadow: 0px 1px 5px 0px rgba(245,81,95,.8);
background: -webkit-linear-gradient(top, #E91E63, #F5515F);
background: linear-gradient(to bottom, #E91E63, #F5515F);
cursor: default;
}
/* Optional content */
.optional {
width: 80%;
max-width: 680px;
margin: 6em auto;
padding: 2em 3em;
box-shadow:
0 3px 12px rgba(0,0,0,0.16),
0 3px 12px rgba(0,0,0,0.23);
}
@media (max-width: 620px) {
body {
font-size: 13px;
line-height: 1.5em;
}
.info {
position: absolute;
width: 100%;
max-width: 100%;
bottom: 0;
right: 0;
}
.inner {
padding: .5em 1.5em;
box-shadow: none;
}
.buttons {
display: none;
}
}
/*
===============================================================
Hi! Welcome to my little playground!
My name is Tobias Bogliolo. 'Open source' by default and always 'responsive',
I'm a publicist, visual designer and frontend developer based in Barcelona.
Here you will find some of my personal experiments. Sometimes usefull,
sometimes simply for fun. You are free to use them for whatever you want
but I would appreciate an attribution from my work. I hope you enjoy it.
===============================================================
*/
$(document).ready(function(){
//Swipe speed:
var tolerance = 100; //px.
var speed = 650; //ms.
//Elements:
var interactiveElements = $('input, button, a');
var itemsLength = $('.panel').length;
var active = 1;
//Background images:
for (i=1; i<=itemsLength; i++){
var $layer = $(".panel:nth-child("+i+")");
var bgImg = $layer.attr("data-img");
$layer.css({
"background": "url("+bgImg+") no-repeat center / cover"
});
};
//Transitions:
setTimeout(function() {
$(".panel").css({
"transition": "cubic-bezier(.4,.95,.5,1.5) "+speed+"ms"
});
}, 200);
//Presets:
$(".panel:not(:first)").addClass("right");
//Swipe:
function swipeScreen() {
$('.swipe').on('mousedown touchstart', function(e) {
var touch = e.originalEvent.touches;
var start = touch ? touch[0].pageX : e.pageX;
var difference;
$(this).on('mousemove touchmove', function(e) {
var contact = e.originalEvent.touches,
end = contact ? contact[0].pageX : e.pageX;
difference = end-start;
});
//On touch end:
$(window).one('mouseup touchend', function(e) {
e.preventDefault();
//Swipe right:
if (active < itemsLength && difference < -tolerance) {
$(".panel:nth-child("+active+")").addClass("left");
$(".panel:nth-child("+(active+1)+")").removeClass("right");
active += 1;
btnDisable();
};
// Swipe left:
if (active > 1 && difference > tolerance) {
$(".panel:nth-child("+(active-1)+")").removeClass("left");
$(".panel:nth-child("+active+")").addClass("right");
active -= 1;
btnDisable();
};
$('.swipe').off('mousemove touchmove');
});
});
};
swipeScreen();
//Prevent swipe on interactive elements:
interactiveElements.on('touchstart touchend touchup', function(e) {
e.stopPropagation();
});
//Buttons:
$(".btn-prev").click(function(){
// Swipe left:
if (active > 1) {
$(".panel:nth-child("+(active-1)+")").removeClass("left");
$(".panel:nth-child("+active+")").addClass("right");
active -= 1;
btnDisable();
};
});
$(".btn-next").click(function(){
//Swipe right:
if (active < itemsLength) {
$(".panel:nth-child("+active+")").addClass("left");
$(".panel:nth-child("+(active+1)+")").removeClass("right");
active += 1;
btnDisable();
};
});
function btnDisable() {
if (active >= itemsLength) {
$(".btn-next").prop("disabled", true);
$(".btn-prev").prop("disabled", false);
}
else if (active <= 1) {
$(".btn-prev").prop("disabled", true);
$(".btn-next").prop("disabled", false);
}
else {
$(".btn-prev, .btn-next").prop("disabled", false);
};
};
});
Also see: Tab Triggers