Posted in
8449
4:28 am, March 1, 2023
Slick slider code testing with slower slides and auto play on videos
additional testing with changes for slick slider videos and auto play
HTML
<div class="slider">
<div>
<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ"></iframe>
</div>
<div>
<iframe src="https://www.youtube.com/embed/2Vv-BfVoq4g"></iframe>
</div>
<div>
<iframe src="https://www.youtube.com/embed/NBfi8OEz0rA"></iframe>
</div>
</div>
CSS
.slider {
width: 80%;
margin: 0 auto;
}
.slick-slide {
margin: 0px 20px;
}
iframe {
width: 100%;
height: 400px;
border: none;
}
Scripts
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css"/>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>
Javascript
$(document).ready(function(){
$('.slider').slick({
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 4000, // set the autoplay speed to 4 seconds
speed: 1000, // set the slider transition speed to 1 second
responsive: [
{
breakpoint: 768,
settings: {
arrows: false,
dots: true
}
}
]
});
// autoplay the YouTube video when it appears
$('.slider').on('beforeChange', function(event, slick, currentSlide, nextSlide){
var video = $(slick.$slides[nextSlide]).find('iframe');
if (video.length) {
video.attr('src', video.attr('src') + '&autoplay=1');
}
});
});
View Statistics
This Week
240
This Month
659
This Year
3695
Add Comment
Other Items in slick slider
Related Search Terms
Other Categories in Code
alpine js apps c css factorio font awesome images linux quick modals sqlite site bugs site updates slick slider sliders testing windows apps apache api apps asp bat bootstrap bootstrap templates charts cookies core css css filters css grid design elements docker domains emoji fancybox fonts foundation framework gimp git html icons ideas image formatting images javascript javascript functions jquery js linux mac misc modals mysql nginx node php php errors php function php functions php simple html dom pi400 python react regex sections simple_html_dom simplepie php site bugs site documentation slick slider sql sqlite ssh sublime svg svg css templates tools virtual box vscode vue webdev windows windows 11 windows commands wordpress