Slick slider pause youtube video when slide change

前端 未结 3 989
说谎
说谎 2021-01-03 00:35

I have created a image slider using Jquery Slick Slider, Its having youtube video clips as well. When page load youtube video is set to 1st slide of the slider and it is aut

相关标签:
3条回答
  • 2021-01-03 00:42

    I would reset the HTML content. It will kill the IFrame and rebuild it.

    var slider =  $('.mainSlider').slick({
        slidesToShow: 1,
        autoplay: false,
        autoplaySpeed: 5000
    });
    
    slider.on('beforeChange', function(event, slick, currentSlide, nextSlide){
        var current = $('.slick-current');
        current.html(current.html());
    });
    
    0 讨论(0)
  • 2021-01-03 00:45

    Adding off of Sequence's answer, this will allow the slider to function even if there is more than one slider on the page.

    $('.mainSlider').on('beforeChange', function(event, slick, currentSlide, nextSlide){
      var current = $(slick.$slides[currentSlide]);
      current.html(current.html());
    });
    
    0 讨论(0)
  • 2021-01-03 01:00

    Check the simplest way, Current slide iframe src reset:

    $('.mainSlider').on('beforeChange', function (event, slick, currentSlide, nextSlide) {
           $('.slick-current iframe').attr('src', $('.slick-current iframe').attr('src'));
    });
    
    0 讨论(0)
提交回复
热议问题