Slick-carousel how to stop autoplay when video is on via youtube api

前端 未结 2 471
花落未央
花落未央 2021-01-21 04:01

Hi i\'m having trouble to get slick carousel (http://kenwheeler.github.io/slick/) to stop the autoplay when I\'m using a youtube clip inside the slider..

Someone said t

2条回答
  •  孤街浪徒
    2021-01-21 04:44

    The onAfterChange is a property of slick that can be passed in the plugin initiation.

    /*  Slick slider init */
    $("#slider").slick({ 
      slidesToShow: 1,
      slidesToScroll: 1,
      arrows: false,
      dots: true,
      autoplay: true,
      autoplaySpeed: 7000,
      infinite: true,
      onAfterChange : function() {
        player.stopVideo();
      }
    });
    

    EDIT

    To stop the slider when the video starts, I guess looking at your code, here's what you could try:

    function onPlayerReady() {
        $("#slide-video").on("click", function() {
    
            // pause the slider
            $('#slider').slick('slickPause');
    
            $(this).css('background','transparent');
            $("#player").show();
            player.playVideo();
        });
    }
    

提交回复
热议问题