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.
<link href="https://fonts.googleapis.com/css?family=Montserrat:700" rel="stylesheet">
<div class="slider_container">
<div class="slides">
<img src="https://media3.giphy.com/media/559q8yZTM50wtLnpaM/giphy.gif" alt="Biker one" class="img">
<img src="https://images.unsplash.com/photo-1558981403-c5f9899a28bc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80" alt="Biker two" class="img">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSPgWmF3rNlB0Bejlc7iAjd8lT6K5POa8LChg&usqp=CAU" alt="Biker three" class="img">
<img src="https://i.pinimg.com/originals/d6/62/15/d662153aee1accf457c81f2334e2d9f3.jpg" alt="Biker four" class="img">
</div>
<nav class="slider_navigation">
<div class="navigation-buttons">
<button class="button button-left"></button>
<button class="button button-right"></button>
<label class="autoplay-controls">
<input type="checkbox" name="autoplay" checked>
<div class="checkmark"></div>
<div class="autoplay-sub">Autoplay</div>
</label>
</div>
<span class="slide_counter"></span>
</nav>
</div>
// *** variables ** //
$animationStyle: cubic-bezier(1, 1.59, .61, .74)
$slideHeight: 100vh
$slideWidth: 100%
$speed: .5s
*
outline: none
font-family: 'Montserrat', sans-serif !important
box-sizing: border-box
body
display: flex
justify-content: center
.button, .checkmark
background-color: #3c709b
border: 0
border-radius: 50%
box-shadow: 0 0 0 0 rgba(190, 190, 220, .2)
color: white
height: 30px
margin: 0 .5rem 0 0
cursor: pointer
position: relative
transition: box-shadow .2s
width: 30px
&:hover
background-color: #25445d
&:active
background: #2196F3
box-shadow: 0 0 15px 40px rgba(220, 220, 250, 0)
.autoplay-controls
cursor: pointer
&:active > .checkmark
background: #2196F3
box-shadow: 0 0 15px 40px rgba(220, 220, 250, 0)
.slider_container
align-items: center
display: flex
flex-direction: column
min-height: $slideHeight
width: $slideWidth
position: relative
.slide_counter
display: flex
align-items: center
.slides
height: $slideHeight
overflow: hidden
position: relative
width: $slideWidth
.navigation-buttons
display: inherit
align-items: center
flex-direction: row
justify-content: center
.slider_navigation
padding: 1rem
background-color: rgba(150,150,150,.6)
display: flex
flex-direction: row
justify-content: space-between
position: absolute
bottom: 0
width: 100%
z-index: 300
.loader
background-color: white
background-image: url('https://editionsdelarose.com/wp-content/themes/edr/img/loading.gif')
background-position: center center
background-repeat: no-repeat
background-size: 150px
height: 100%
position: absolute
width: 100%
z-index: 300
input
display: none
&:checked ~ .checkmark:after
display: block
&:checked ~ .checkmark
background-color: #2196F3
.autoplay-sub
float: left
line-height: 30px
font-size: .7rem
.checkmark
float: left
&:after
content: ""
position: absolute
display: none
left: 11px
top: 7px
width: 5px
height: 10px
border: solid white
border-width: 0 3px 3px 0
transform: rotate(45deg)
.button-left:after, .button-right:after
border: solid white
border-width: 0 3px 3px 0
content: ""
display: block
height: 8px
position: absolute
width: 8px
.button-left:after
left: 11px
top: 10px
transform: rotate(135deg)
.button-right:after
left: 7px
top: 10px
transform: rotate(-45deg)
// *** animation in and out *** //
// *** left *** //
.inright
animation: goInL $speed $animationStyle
position: relative
z-index: 300 !important
@keyframes goInL
0%
left: -$slideWidth
100%
left: 0
.outright
animation: goOutL $speed $animationStyle
position: relative
z-index: 200
@keyframes goOutL
0%
left: 0
100%
left: $slideWidth
// *** right *** //
.inleft
animation: goInR $speed $animationStyle
position: relative
z-index: 300 !important
@keyframes goInR
0%
left: $slideWidth
100%
left: 0
.outleft
animation: goOutR $speed $animationStyle
position: relative
z-index: 200
@keyframes goOutR
0%
left: 0
100%
left: -$slideWidth
.img
left: 0
min-height: $slideHeight
max-height: $slideHeight
object-fit: cover
position: absolute
width: $slideWidth
background-color: silver
&:first-child
z-index: 100
// *** VARIABLES *** //
const autoBox = document.querySelector("input[name=autoplay]"),
autoDir = "left", // left or right
btnLeft = document.querySelector(".button-left"),
btnRight = document.querySelector(".button-right"),
loader = document.createElement("div"),
counter = document.querySelector(".slide_counter"),
slider = document.querySelector(".slides"),
slides = document.querySelectorAll(".slides img"),
SPEED = 2000; // = 2s
let count = 0,
autoplay = null;
// *** Create loader *** //
loader.classList.add("loader");
slider.appendChild(loader);
// *** Hide loader when everything is loaded *** //
document.onreadystatechange = () => {
if (document.readyState === "complete") {
loader.hidden = true;
}
};
// *** Initialize counter *** //
updateCounter();
// *** Start slideshow if hardcoded -checked- *** //
if (autoBox.checked) {
autoplay = setInterval(slide.bind(this, "auto"), SPEED);
}
// *** Listen buttons for call *** //
btnLeft.addEventListener("click", () => slide("right"));
btnRight.addEventListener("click", () => slide("left"));
autoBox.addEventListener("change", () => {
// *** If autoplay is checked then play slides, if not then stop *** //
if (autoBox.checked) {
autoplay = setInterval(() => slide("auto"), SPEED);
} else {
stopInterval();
}
});
// *** Change slide *** //
function slide(direction) {
// *** If left or right button were clicked, stop autoplay *** //
if (direction === "right" || direction === "left") {
stopInterval();
}
// *** If direction is 'auto' then slide to 'autoDir' - variable at the top, otherwise swipe in choosen direction *** //
direction = direction == "auto" ? autoDir : direction;
// *** Clear all previously added classes from every photo. *** //
[].forEach.call(slides, (photo) => {
photo.classList.remove("outleft", "outright");
});
slides[count].classList.remove("inleft", "inright");
// *** Add class from sliding out photo *** //
slides[count].classList.add("out" + direction);
// *** Update counter - if clicked right button count -1, else count +1 *** //
count = direction == "right" ? count - 1 : count + 1;
// *** Looping slides *** //
// *** if reached end go to first slide *** //
if (count > slides.length - 1) {
count = count % slides.length;
}
// *** if reached first go to last one *** //
if (count < 0) {
count = slides.length - 1;
}
// *** Add class for sliding in photo *** //
slides[count].classList.add("in" + direction);
// *** Update counter *** //
updateCounter();
}
// *** counter *** //
function updateCounter(){
counter.innerText = count + 1 + " of " + slides.length;
}
// *** Stop slideshow *** //
function stopInterval() {
clearInterval(autoplay);
autoplay = null;
autoBox.checked = false;
}
// *** The End *** //
Also see: Tab Triggers