<div class="video-carousel-wrapper">
<button class="carousel-btn left" id="prevBtn">❮</button>
<div class="video-carousel" id="videoCarousel">
<div class="video-container">
<video src="https://cdn.shopify.com/videos/c/o/v/259c60dae44d4e068878c5900de6b29b.mp4" playsinline="" muted=""></video>
<button class="mute-btn">🔇</button>
</div>
<div class="video-container">
<video src="https://cdn.shopify.com/videos/c/o/v/3a8fb339b0574da78551c521fa5cec2c.mp4" playsinline="" muted=""></video>
<button class="mute-btn">🔇</button>
</div>
<div class="video-container">
<video src="https://cdn.shopify.com/videos/c/o/v/5c7a6b042fbd41fea60d77fc56bb2989.mp4" playsinline="" muted=""></video>
<button class="mute-btn">🔇</button>
</div>
<div class="video-container">
<video src="https://cdn.shopify.com/videos/c/o/v/32dfbdbf3c2f448aa285faa2ef2caa7e.mp4" playsinline="" muted=""></video>
<button class="mute-btn">🔇</button>
</div>
</div>
<button class="carousel-btn right" id="nextBtn">❯</button>
</div>
<style>
.video-carousel-wrapper {
position: relative;
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: #fff;
overflow: hidden;
}
.video-carousel {
display: flex;
align-items: center;
transition: transform 0.6s ease;
will-change: transform;
}
.video-container {
position: relative;
flex: 0 0 25%;
max-height: 70vh;
transition: transform 0.5s ease, flex 0.5s ease;
display: flex;
justify-content: center;
align-items: center;
margin: 0 8px;
}
.video-container video {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 12px;
display: block;
}
.video-container.active {
flex: 0 0 40%;
transform: scale(1.05);
z-index: 2;
}
.mute-btn {
position: absolute;
bottom: 15px;
right: 15px;
background: rgba(0,0,0,0.5);
border: none;
color: white;
font-size: 18px;
padding: 8px;
border-radius: 50%;
cursor: pointer;
z-index: 5;
-webkit-tap-highlight-color: transparent;
}
.carousel-btn {
position: absolute;
top: 50%;
transform: translateY(-50%);
background: rgba(0,0,0,0.45);
border: none;
color: white;
font-size: 32px;
cursor: pointer;
padding: 12px 16px;
border-radius: 50%;
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
touch-action: manipulation;
-webkit-tap-highlight-color: transparent;
}
.carousel-btn.left { left: 20px; }
.carousel-btn.right { right: 20px; }
/* ✅ Ajustes móviles (flechas se mantienen iguales que en escritorio) */
@media (max-width: 768px) {
.video-carousel-wrapper { height: 65vh; }
.video-container { flex: 0 0 85%; max-height: 85vh; margin: 0 6px; }
.video-container.active { flex: 0 0 92%; transform: scale(1.03); }
.mute-btn { bottom: 10px; right: 10px; font-size: 16px; padding: 6px; }
}
/* Foco accesibilidad */
.carousel-btn:focus, .mute-btn:focus, .video-container:focus {
outline: 2px solid rgba(0,150,136,0.6);
outline-offset: 2px;
}
</style>
<script>
(function(){
const wrapper = document.querySelector('.video-carousel-wrapper');
const carousel = document.getElementById('videoCarousel');
let containers = Array.from(carousel.querySelectorAll('.video-container'));
let videos = containers.map(c => c.querySelector('video'));
let muteButtons = containers.map(c => c.querySelector('.mute-btn'));
let activeIndex = Math.floor(containers.length / 2);
if (!carousel || containers.length === 0) return;
function centerElementAt(index) {
containers = Array.from(carousel.querySelectorAll('.video-container'));
videos = containers.map(c => c.querySelector('video'));
muteButtons = containers.map(c => c.querySelector('.mute-btn'));
index = Math.max(0, Math.min(index, containers.length - 1));
containers.forEach((c, i) => {
c.classList.remove('active');
const v = videos[i];
if (v) { v.pause(); v.currentTime = 0; }
});
const target = containers[index];
if (!target) return;
target.classList.add('active');
requestAnimationFrame(() => {
const wrapperWidth = wrapper.clientWidth;
const elLeft = target.offsetLeft;
const elWidth = target.offsetWidth;
const elCenter = elLeft + elWidth / 2;
const translateX = (wrapperWidth / 2) - elCenter;
carousel.style.transform = `translateX(${translateX}px)`;
const centralVideo = target.querySelector('video');
if (centralVideo) {
centralVideo.muted = true;
centralVideo.play().catch(()=>{});
}
muteButtons.forEach((btn, i) => {
if (!btn) return;
const v = videos[i];
btn.textContent = v && !v.muted ? "🔊" : "🔇";
});
});
}
function nextVideo() {
activeIndex = (activeIndex + 1) % containers.length;
centerElementAt(activeIndex);
}
function prevVideo() {
activeIndex = (activeIndex - 1 + containers.length) % containers.length;
centerElementAt(activeIndex);
}
document.getElementById('nextBtn').addEventListener('click', nextVideo);
document.getElementById('prevBtn').addEventListener('click', prevVideo);
containers.forEach((c, idx) => {
const v = videos[idx];
const btn = muteButtons[idx];
if (!btn || !v) return;
btn.addEventListener('click', (e) => {
e.stopPropagation();
v.muted = !v.muted;
btn.textContent = v.muted ? "🔇" : "🔊";
});
v.addEventListener('ended', () => {
setTimeout(nextVideo, 200);
});
c.addEventListener('click', () => {
activeIndex = containers.indexOf(c);
centerElementAt(activeIndex);
});
});
function debounce(fn, wait = 120){
let t;
return function(){ clearTimeout(t); t = setTimeout(fn, wait); };
}
window.addEventListener('resize', debounce(() => centerElementAt(activeIndex)));
if (containers.length === 1) activeIndex = 0;
if (activeIndex >= containers.length) activeIndex = Math.floor(containers.length / 2);
centerElementAt(activeIndex);
})();
</script>