dimsemenov / Magnific-Popup

Light and responsive lightbox script with focus on performance.
http://dimsemenov.com/plugins/magnific-popup/
MIT License
11.39k stars 3.48k forks source link

Take control of each vimeo video under a Magnific-Popup gallery. #1138

Open rashed-jitu opened 4 years ago

rashed-jitu commented 4 years ago

Hi, I want to take control on my each vimeo video currently it is playing under the popup iframe. I have tried this it not working properly.

$('.selector).magnificPopup({
            type: "iframe",
            gallery: {
                enabled: true
            },
            iframe: {
                patterns: {
                    vimeo: {
                        index: 'vimeo.com/',
                        id: '/',
                        src: '//player.vimeo.com/video/%id%?autoplay=1&api=1&player_id=playall'
                    },
                }
            },
            callbacks: {
                change: function () {
                    var tryingNumber = 15;
                    var tried = 0;
                    var instance = this;
                    var element = [];
                    setTimeout(function tryToGetIframe() {
                        element = $('.mfp-iframe');
                        if (!element.length && tryingNumber > tried) {
                            tried++;
                            setTimeout(tryToGetIframe, 5000);
                        } else if (element.length) {
                            var player = new Vimeo.Player(element);
                            player.on('ended', function () {
                                console.log('ended');
                                instance.next();
                            })
                        }
                    }, 5000)
                }
            }
        });

Its works for the first item okay. but for next items it does not work.