Posted in slick slider
6004
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
99
This Month
524
This Year
1249

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 was a little kid, I was really scared of the dark. But then I came to understand, dark just means the absence of photons in the visible wavelength -- 400 to 700 nanometers. Then i thought, well, its really silly to be afraid of a lack of photons. Then i wasn't afraid of the dark anymore after that.
Elon Musk
Random CSS Property

:nth-last-child()

The :nth-last-child() CSS pseudo-class matches elements based on their position among a group of siblings, counting from the end.
:nth-last-child css reference