admin管理员组

文章数量:1333451

Hope you can help me. I read and read again the documentation of Magnific Popup, but I'm not good enough with javascript.

1- I open a popup with this link :

<a href="mysubpage.html" class="pop">OPEN POPUP</a>

and this javascript :

$('.pop').magnificPopup({ type:'iframe', showCloseBtn : true, closeOnBgClick : true, midClick: true });

2- in my popup, I would like a button 'CLOSE' to close the pop-up.

I try this but it doesn't worked :

<input type="button" value="CLOSE" onclick="magnificPopup.close();" />
<input type="button" value="CLOSE" onclick="$.magnificPopup.close();" />
<input type="button" value="CLOSE" onclick="$('pop').magnificPopup.close();" />
<a href="#" class="mpf-close">CLOSE</a>
<a href="#" onclick="magnificPopup.close();">CLOSE</a>

I read I need to place this code :

var magnificPopup = $.magnificPopup.instance; 

But where ? in which page ? with what syntaxe ?

Magnific Popup documentation : LINK

Thanks for helping. Have a good day ;-)

Hope you can help me. I read and read again the documentation of Magnific Popup, but I'm not good enough with javascript.

1- I open a popup with this link :

<a href="mysubpage.html" class="pop">OPEN POPUP</a>

and this javascript :

$('.pop').magnificPopup({ type:'iframe', showCloseBtn : true, closeOnBgClick : true, midClick: true });

2- in my popup, I would like a button 'CLOSE' to close the pop-up.

I try this but it doesn't worked :

<input type="button" value="CLOSE" onclick="magnificPopup.close();" />
<input type="button" value="CLOSE" onclick="$.magnificPopup.close();" />
<input type="button" value="CLOSE" onclick="$('pop').magnificPopup.close();" />
<a href="#" class="mpf-close">CLOSE</a>
<a href="#" onclick="magnificPopup.close();">CLOSE</a>

I read I need to place this code :

var magnificPopup = $.magnificPopup.instance; 

But where ? in which page ? with what syntaxe ?

Magnific Popup documentation : LINK

Thanks for helping. Have a good day ;-)

Share Improve this question asked Aug 3, 2014 at 14:27 KipkoolKipkool 432 silver badges4 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

The following will work. Add button (or any other element)

<button id="my-custom-close">close</button>

... and this javascript

$('#my-custom-close').click(function(){
    //This will close popup dialog opened using $.magnificPopup.open()
    $.magnificPopup.close();
});

There is an option to add a close button, and option to display inside popup. I would not use custom buttons or elements to try to close the popup, it should be included inside the popup once you have these two options set.

<a href='#' class='pop'>Open Popup</a>

$('.pop').magnificPopup({ 
  // main options
  showCloseBtn: true,
  closeBtnInside: true,

  gallery: {
    // options for gallery
    enabled: true
  },
  image: {
    // options for image content type
    titleSrc: 'title'
  }

});

本文标签: javascriptjQuery magnificpopupcreate a button inside the popup to close the popupStack Overflow