Posted in slick slider
6042
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
93
This Month
321
This Year
1287

No Items Found.

Add Comment
Type in a Nick Name here
 
Related Search Terms
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
When I realized that, no individual step is hard in any process. Building this airport I'm standing in right now started with a guy writing the architectural plans on paper. That's not hard for him to do. Then laying the first beam isn't had. The whole thing is really hard. So, just take each step kind of piece by piece and when I was able to do that and stop trying to chase this prize and started putting in the work, things just started coming together.
Unknown
Random CSS Property

background

The background shorthand CSS property sets all background style properties at once, such as color, image, origin and size, or repeat method.
background css reference