Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <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>
              
            
!

CSS

              
                // *** 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
              
            
!

JS

              
                // *** 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 *** //

              
            
!
999px

Console