Spaces:
Running
Running
File size: 5,728 Bytes
b056989 3242a9c b056989 a37eff3 b056989 3242a9c b056989 718374f b056989 718374f b056989 2d83b1b b056989 6d6fd27 718374f b056989 e64799d 718374f b056989 e64799d 718374f b056989 718374f b056989 718374f b056989 a37eff3 718374f b056989 2a6f17d 718374f b056989 85c1b0c b056989 37bb41b 85c1b0c 9bf5849 b056989 9bf5849 37bb41b 85c1b0c 9bf5849 a37eff3 9bf5849 37bb41b 9bf5849 b056989 a37eff3 9bf5849 37bb41b b056989 a37eff3 85c1b0c a37eff3 b056989 37bb41b b056989 a37eff3 b056989 37bb41b b056989 9bf5849 b056989 37bb41b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
<!DOCTYPE html>
<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> |