Spaces:
Running
Running
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Video Comparison Slider</title> | |
<style> | |
:root { | |
--container-width: 90vw; /* Define a custom property for width */ | |
} | |
body, html { | |
margin: 0; | |
padding: 0; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 100vh; | |
background-color: black; | |
} | |
.video-container { | |
position: relative; | |
width: var(--container-width); /* Use the custom property for width */ | |
height: calc(var(--container-width) * 9 / 16); /* Calculate height based on width */ | |
overflow: hidden; | |
} | |
video { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
object-fit: cover; | |
} | |
.second-video { | |
clip-path: inset(0 50% 0 0); | |
} | |
.slider { | |
position: absolute; | |
top: 0; | |
left: 30%; | |
width: 2px; | |
height: 100%; | |
background: rgb(0, 80, 150); | |
cursor: ew-resize; | |
z-index: 10; | |
animation: slide-animation 5s ease-in-out forwards; | |
border-radius: 4px; | |
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); | |
} | |
.slider::before, | |
.slider::after { | |
content: ''; | |
position: absolute; | |
top: 80%; | |
transform: translateY(-50%); | |
width: 30px; | |
height: 30px; | |
background-size: contain; | |
background-repeat: no-repeat; | |
transition: opacity 0.3s; | |
} | |
.slider::before { | |
left: -27px; | |
/* Simplified arrowhead pointing left */ | |
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="rgb(0, 80, 150)"><polygon points="14,7 8,12 14,17"/></svg>'); | |
} | |
.slider::after { | |
right: -27px; | |
/* Simplified arrowhead pointing right */ | |
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="rgb(0, 80, 150)"><polygon points="10,7 16,12 10,17"/></svg>'); | |
} | |
.slider.ready:hover::before, | |
.slider.ready:hover::after { | |
transform: translateY(-50%) scale(1.2); | |
} | |
.slider.ready::before, | |
.slider.ready::after { | |
opacity: 0.7; | |
} | |
.slider.ready:hover::before, | |
.slider.ready:hover::after { | |
opacity: 1; | |
} | |
@keyframes slide-animation { | |
0% { | |
left: 100%; | |
} | |
10% { | |
left: 80%; | |
} | |
20% { | |
left: 85%; | |
} | |
50% { | |
left: 20%; | |
} | |
70% { | |
left: 60%; | |
} | |
100% { | |
left: 30%; | |
} | |
} | |
</style> | |
</head> | |
<body> | |
<div class="video-container" id="videoContainer"> | |
<video id="video1" src="flir_brain_padded.mp4" playsinline autoplay loop muted></video> | |
<video id="video2" class="second-video" src="flir_20240905_120243.mp4" playsinline autoplay loop muted></video> | |
<div class="slider" id="slider"></div> | |
</div> | |
<script> | |
const slider = document.getElementById('slider'); | |
const container = document.getElementById('videoContainer'); | |
const video2 = document.getElementById('video2'); | |
let isDragging = false; | |
// Mouse events for slider | |
slider.addEventListener('mousedown', () => isDragging = true); | |
window.addEventListener('mouseup', () => isDragging = false); | |
window.addEventListener('mousemove', (event) => { | |
if (!isDragging) return; | |
handleSlide(event.clientX); | |
}); | |
// Touch events for slider | |
slider.addEventListener('touchstart', () => isDragging = true); | |
window.addEventListener('touchend', () => isDragging = false); | |
window.addEventListener('touchmove', (event) => { | |
if (!isDragging) return; | |
handleSlide(event.touches[0].clientX); | |
}); | |
function handleSlide(positionX) { | |
const rect = container.getBoundingClientRect(); | |
const offsetX = positionX - rect.left; | |
const sliderPosition = Math.max(0, Math.min(offsetX, rect.width)); | |
// Move slider position | |
slider.style.left = `${sliderPosition}px`; | |
// Adjust second video visibility using clip-path | |
video2.style.clipPath = `inset(0 ${rect.width - sliderPosition}px 0 0)`; | |
} | |
// Function to update clip-path in real-time | |
function updateClipPath() { | |
const rect = container.getBoundingClientRect(); | |
const sliderPosition = parseFloat(window.getComputedStyle(slider).left); | |
video2.style.clipPath = `inset(0 ${rect.width - sliderPosition}px 0 0)`; | |
requestAnimationFrame(updateClipPath); | |
} | |
// Enable user control after the animation ends | |
slider.addEventListener('animationend', () => { | |
slider.classList.add('ready'); | |
slider.style.animation = 'none'; | |
slider.style.cursor = 'ew-resize'; | |
slider.style.pointerEvents = 'auto'; | |
}); | |
// Start updating clip-path once the page loads | |
window.onload = () => updateClipPath(); | |
</script> | |
</body> | |
</html> |