Posted in slick slider
6010
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
105
This Month
530
This Year
1255

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
The problem with hoarding is you end up living off your reserves. Eventually, you’ll become stale. If you give away everything you have, you are left with nothing. This forces you to look, to be aware, to replenish. . . . Somehow the more you give away, the more comes back to you.
Paul Arden
Random CSS Property

line-break

The line-break CSS property sets how to break lines of Chinese, Japanese, or Korean (CJK) text when working with punctuation and symbols.
line-break css reference