小编Kyl*_*uel的帖子

使用on()时,MagnificPopup无法首次单击

我已经委托了$(document)一个click带有类的动态添加元素的方法.popup-youtube.唯一的问题是,我无法让弹出窗口正常工作.

这是我的脚本:

$(this).on("click", ".popup-youtube", function(e){

        // prevent default action
        e.preventDefault();

        $(this).magnificPopup({
            type: 'iframe',
            iframe: {
                markup: '<div class="mfp-iframe-scaler">'+
                    '<div class="mfp-close"></div>'+
                    '<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>'+
                    '</div>', // HTML markup of popup, `mfp-close` will be replaced by the close button
                patterns: {
                    youtube: {
                        index: 'youtube.com/', // String that detects type of video (in this case YouTube). Simply via url.indexOf(index).
                        id: 'v=', // String that splits URL in a two parts, second part should be %id% …
Run Code Online (Sandbox Code Playgroud)

javascript jquery magnific-popup

1
推荐指数
1
解决办法
1774
查看次数

标签 统计

javascript ×1

jquery ×1

magnific-popup ×1