我已经委托了$(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)