I have made a horizontal carousel of videos (and captions) using Twitter Bootstrap 4, the perfect-scrollbar plugin and some custom CSS.
My goal is to animate the width of the videos from 0 to 100%, with a smooth transition. I want to animate the width only but the height also gets animated. The code I have written so far:
if ($('#carousel').length > 0) {
var ps = new PerfectScrollbar('#carousel', {
useBothWheelAxes: true,
maxScrollbarLength: 100
});
$('.video-box').each(function() {
var vid = $(this).find('video');
vid.closest('.video-container').addClass('loaded');
vid.hover(function() {
$(this).get(0).play();
}, function() {
$(this).get(0).pause();
})
});
}
.hero {
height: 100vh;
background: #111;
}
#carousel {
display: flex;
list-style-type: none;
position: relative;
min-width: 100vw;
margin: 0;
padding: 0;
justify-content: left;
align-items: center;
}
#carousel li {
padding: 0;
flex-shrink: 0;
position: relative;
}
#carousel li a {
text-decoration: none;
color: #fff;
display: block;
}
#carousel li .video-container video {
transition: width 1s ease-in-out;
width: 0;
height: 100%;
}
#carousel li .video-container.loaded video {
width: 100%;
}
#carousel li .caption {
padding: 20px 20px 0 20px;
}
#carousel li h2 {
font-size: 22px;
font-weight: 900;
line-height: 1;
margin: 0;
padding: 0;
}
#carousel li p {
font-size: 9px;
padding: 0;
margin: 5px 0 0 0;
}
#carousel .ps__rail-x {
background: #5C5C5C;
height: 3px;
margin: 0 40% 10vh 40%;
}
#carousel .ps__thumb-x {
height: 3px;
margin-bottom: -2px;
border-radius: 0;
background: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://code-love.tk/demos/prop/lib/js/perfect-scrollbar.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="http://code-love.tk/demos/prop/lib/css/perfect-scrollbar.css" />
<div class="hero carousel-container d-flex">
<ul id="carousel">
<li class="video-box col-xs-12 col-sm-6 col-md-4">
<a href="caz.html">
<div class="video-container">
<video src="//code-love.tk/video/commerciala.mp4" loop muted></video>
</div>
<div class="caption">
<h2>Lorem ipsun dolor</h2>
<p>A true story</p>
</div>
</a>
</li>
<li class="video-box col-xs-12 col-sm-6 col-md-4">
<a href="#">
<div class="video-container">
<video src="//code-love.tk/video/commerciala.mp4" loop muted></video>
</div>
<div class="caption">
<h2>Lorem</h2>
<p>Lorem ipsum dolor sit</p>
</div>
</a>
</li>
<li class="video-box col-xs-12 col-sm-6 col-md-4">
<a href="#">
<div class="video-container">
<video src="//code-love.tk/video/flamenco.mp4" loop muted></video>
</div>
<div class="caption">
<h2>Lorem ipsum</h2>
<p>Lorem ipsum dolor sit.</p>
</div>
</a>
</li>
<li class="video-box col-xs-12 col-sm-6 col-md-4">
<a href="#">
<video src="//code-love.tk/video/koffee.mp4" loop muted></video>
<div class="caption">
<h2>Into the wild</h2>
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
</a>
</li>
</ul>
</div>
The "live" page is HERE. What am I doing wrong? What shall I do with the videos?