How to embed youtube video in magnific popup?

前端 未结 3 2046
夕颜
夕颜 2021-02-01 06:49

i have magnific popup plugin.but it not showing the video on popup How to embed youtube video in magnific popup?

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-01 07:12

    By default Magnific Popup supports only one type of URL for each service so I extent it for support almost every video URL type of YouTube/Vimeo:

    http://dimsemenov.com/plugins/magnific-popup/documentation.html#iframe-type

    $('.my-selector').magnificPopup({
        type: 'iframe',
        iframe: {
            patterns: {
                youtube: {
                    index: 'youtube.com/', 
                    id: function(url) {        
                        var m = url.match(/[\\?\\&]v=([^\\?\\&]+)/);
                        if ( !m || !m[1] ) return null;
                        return m[1];
                    },
                    src: '//www.youtube.com/embed/%id%?autoplay=1'
                },
                vimeo: {
                    index: 'vimeo.com/', 
                    id: function(url) {        
                        var m = url.match(/(https?:\/\/)?(www.)?(player.)?vimeo.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/);
                        if ( !m || !m[5] ) return null;
                        return m[5];
                    },
                    src: '//player.vimeo.com/video/%id%?autoplay=1'
                }
            }
        }
    });
    

    Just copy those two property (iframe, type) and add them to your Magnific Popup.

提交回复
热议问题