2015-05-19 55 views
0

我在使用jQuery的get()方法加載內容後,使用MagnificPopup顯示彈出窗口。當get()調用完成,我想顯示下面的彈出:MagnificPopup without button click

<div id="tagsearch-popup" class="panel panel-default mfp-hide"> 
    <div class="panel-heading">Tag Search</div> 
    <div class="panel-body"> 
     <div class="col-xs-12 no-padding"> 
      Example 
     </div> 
    </div> 
</div> 

這是我使用jQuery。

$.get(url, function (data) { 
    success: { 
     $("#recalculation-guid").html(data); 
     // Display popup now 
    } 
}); 

但是,當我查看MagnificPopup示例時,我只能找到將彈出窗口綁定到按鈕的示例。我想以編程方式創建它。

如何使用MagnificPopup將上述<div>轉換爲彈出式菜單,而無需單擊按鈕?

回答

2

,有一個名爲open方法:

$.magnificPopup.open({ 
    items: { 
    src: 'someimage.jpg' 
    }, 
    type: 'image' 

    // You may add options here, they're exactly the same as for $.fn.magnificPopup call 
    // Note that some settings that rely on click event (like disableOn or midClick) will not work here 
}, 0); 
//and also close, if you're into that ;) 
$.magnificPopup.close(); 

因此,在你的代碼:

$.get(url, function (data) { 
    success: { 
    $("#recalculation-guid").html(data); 
    // Display popup now 
    $.magnificPopup.open({...}); 
    } 
}); 
0

這個例子可以幫助你:

$("a").click(function() { 
    alert("clicked"); 
    // your instantiation 
}); 
$("a").click(); 

你需要做的是什麼觸發你實例化MagnificPopup點擊。