检查以下更新:
我就是这么做的:
-
没有接触到初始化任何FE的JS
.my-modal
班
-
我编辑了这些按钮的类
.我的模态
进入之内
.my-custom-modal
(例如)
-
已在上初始化MagnicPopup
.我的自定义模式
并添加以下内容以在打开模式之前触发事件:
$('.my-custom-modal').magnificPopup({
type: 'inline',
midClick: true
}).on('mfpBeforeOpen', function () {
// 'this' is the current button that triggered the modal
console.log(this);
});
更新
上面的方法有效,但是'this'变量没有返回实际的按钮,但看起来像是页面中的第一个按钮。
以下各项应正常工作:
$('.my-custom-modal').magnificPopup({
type: 'inline',
midClick: true,
callbacks: {
open: function () {
var mp = $.magnificPopup.instance,
btn = $(mp.currItem.el[0]);
//btn is the actual button being clicked
console.log(btn);
}
}
});