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

              
                <!-- Image Slider Container -->
<div class="image-slider-container">
	<!-- Upper Image -->
	<div class="image background-image"></div>
	<!-- Lower Image -->
	<div class="image foreground-image"></div>

	<!-- Range Input -->
	<input id="range-slider" class="range-slider" name="slider" type="range" min="1" max="100" value="50" />

	<!-- Slider Control -->
	<div class="slider-control">
		<span class="slider-control-btn left"></span>
		<span class="slider-control-btn right"></span>
	</div>
</div>
              
            
!

CSS

              
                // Variables
$background-color: #333;
$image-url: "https://cdn.pixabay.com/photo/2014/04/17/23/26/environmental-protection-326923_1280.jpg";

// Mixin
@mixin center() {
	display: flex;
	justify-content: center;
	align-items: center;
}

// Reset spacings
*::before,
*,
*::after {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

// General settings
body {
	display: flex;
	width: 100%;
	height: 100vh;
	justify-content: center;
	align-items: center;
	background: $background-color;
	perspective: 200px;
	box-shadow: inset 0 0 200px;
	animation: focusToSlider 500ms ease-out reverse;
}

// Image Slider Container
.image-slider-container {
	position: relative;
	width: 800px;
	height: 500px;
	border: 5px solid #fff;
	border-radius: 20px;
	overflow: hidden;
	transform: scale(1) rotate(0);
	transition: transform 300ms ease;

	transform-style: preserve-3d;

	.image {
		position: absolute;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		background-size: cover;
		background-position: center;

		&:nth-child(1) {
			background: url($image-url);
			filter: grayscale(100%) blur(2.5px);
		}

		&:nth-child(2) {
			background: url($image-url);
			filter: saturate(1.3);
			width: 50%;
		}
	}

	// Range Input
	.range-slider {
		position: absolute;
		@include center;
		width: 100%;
		height: 100%;
		margin: 0;
		background: rgba(#f2f2f2, 0.2);
		outline: none;
		-webkit-appearance: none;
		appearance: none;
		z-index: 2;
		transition: all 200ms linear;

		&:hover {
			background: rgba(#f2f2f2, 0.1);
		}

		&::-webkit-slider-thumb {
			-webkit-appearance: none;
			appearance: none;
			width: 6px;
			height: 800px;
			background: white;
			cursor: move;
			transition: all 300ms ease;
		}
	}
}

// Slider Control
.slider-control {
	z-index: 0;
	position: relative;
	display: block;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	background: white;
	top: 50%;
	left: 50%;
	transform: translate(-60%, -50%);
	cursor: grab; // Changed cursor to "grab" for better user experience

	&::after,
	&::before {
		font-family: "Font Awesome 5 Free";
		font-weight: 900;
		position: absolute;
		top: 50%;
		transform: translateY(-50%);
	}

	&::after {
		content: "\f054"; // Right arrow icon
		right: 3px;
	}

	&::before {
		content: "\f053"; // Left arrow icon
		left: 3px;
	}
}

@keyframes focusToSlider {
	from {
		box-shadow: inset 0 0 200px;
	}

	to {
		box-shadow: inset 0 0 0 0;
	}
}

              
            
!

JS

              
                // set vars
const imageSliderContainer = document.querySelector(".image-slider-container");
const slider = document.getElementById("range-slider");
const image = document.getElementsByClassName("image")[1];
const buttonRange = document.getElementsByClassName("slider-control")[0];

// Move slider and buttonRange at change of value
slider.addEventListener("input", (e) => {
	const sliderPos = e.target.value;

	image.style.width = sliderPos + "%";
	buttonRange.style.left = sliderPos + "%";
});

imageSliderContainer.addEventListener("mousemove", (e) => {
	const reduceMovement = (n) => n / 25;

	imageSliderContainer.animate(
		{
			transform: `scale(1.03) rotateX(${reduceMovement(
				e.movementY
			)}deg) rotateY(${reduceMovement(e.movementX)}deg)`
		},
		{ duration: 1200 }
	);
});

imageSliderContainer.addEventListener("mouseout", (e) => {
	imageSliderContainer.animate(
		{ transform: `scale(1) rotateX(0deg) rotateY(0deg)` },
		{ duration: 250, fill: "forwards" }
	);
});

              
            
!
999px

Console