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

前端 未结 2 468
花落未央
花落未央 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:50

    I found a solution to my problem:

    function onPlayerReady() {
            $("#slide-video").on("click", function() {
                $(this).hover(function(){
                    slider.slick('slickPause');
                });
                $(this).css('background','transparent');
                $("#player").show();
                player.playVideo();
            });
        }
    
        function onPlayerStateChange(event) {
            if(event.data === 0 || event.data === 2) {
                $(".countdown").fadeIn();
            }
    
            if(event.data === 1) {
                $(".countdown").fadeOut();
            }
    
            if( 1 === event.data || 2 === event.data || 3 === event.data) {
                slider.slick('slickPause');
    
            } else {
                slider.slick('slickPlay');
            }
        }
    

    This worked on my end in chrome & Safari.. Firefox doesnt work on and IE I cant try since im not on a pc but on a MAC, but thats why i putted a hover function incase someone want to have the mouse there?

    update: Okay it works now with all.. its just after you pause the video and then resume it AFTER the slider has gone once it will not use the slickPause function anymore.

提交回复
热议问题