Magnific popup:获取回调中的当前元素 [英] Magnific popup: Get current element in callback

查看:242
本文介绍了Magnific popup:获取回调中的当前元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Magnific Popup中,我想在链接中获取一个属性,并在回调函数中使用它(使用回调:open)在DOM中进行一些更改。

In Magnific Popup, I want to get an attribute in the link that is clicked and use it in a callback function (using callbacks: open) to make some changes in the DOM.

我该怎么做?例如,在下面的代码中,它应该返回'它工作'到控制台。相反,它打印'不工作'。请帮助!!

How can I do this? For example, in the code below, it should return 'it works' to console. Instead it prints 'doesnt work'. Please help!!

<a href="#test-popup" class="open-popup-link" myatt="hello">Show inline popup</a>

<script src="jquery.magnetic.custom.js"></script>

<script>

    $(document).ready(function() {
      $('.open-popup-link').magnificPopup({
        type:'inline',
        midClick: true,
        callbacks: {
          open: function() {

            if ($(this).attr('myatt')=="hello") 
            { 
              // do something 
              console.log("it works");
            }
            else
            {
              console.log("doesnt work");
            }

          },
          close: function() {

          }
        }

      });
    });

</script>

<div id="test-popup" class="white-popup mfp-hide">
  Popup content
</div>


推荐答案

对于Magnific Popup v0.9.8

For Magnific Popup v0.9.8

var magnificPopup = $.magnificPopup.instance,
              cur = magnificPopup.st.el;
console.log(cur.attr('myatt'));

这篇关于Magnific popup:获取回调中的当前元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆