如何通过 jquery 关闭 magnific popup
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16912529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to close magnific popup by jquery
提问by Sanjay
I m using magnific popup in my project. To close this popup by jquery I am using $('.mfp-close').click(); and it's working but I have need to close by another way. Plz help me if any other way. Thanks in advance
我在我的项目中使用了 magnific popup。要通过 jquery 关闭此弹出窗口,我正在使用 $('.mfp-close').click(); 它正在工作,但我需要以另一种方式关闭。如果有任何其他方式,请帮助我。提前致谢
回答by Konstantin Kalbazov
Just use $.magnificPopup.close()
只需使用 $.magnificPopup.close()
回答by Bobby5193
try this:
尝试这个:
var magnificPopup = $.magnificPopup.instance;
// save instance in magnificPopup variable
magnificPopup.close();
// Close popup that is currently opened
回答by Lem
Take a look here http://dimsemenov.com/plugins/magnific-popup/documentation.html#api
看看这里http://dimsemenov.com/plugins/magnific-popup/documentation.html#api
These are some ways you can close this pop up:
这些是您可以关闭此弹出窗口的一些方法:
var magnificPopup = $.magnificPopup.instance; // save instance in magnificPopup variable
magnificPopup.close(); // Close popup that is currently opened
or
或者
$.magnificPopup.close();
$.magnificPopup.close();
or
或者
$('your-selector').magnificPopup('close');
$('your-selector').magnificPopup('close');
For me, only the third one worked efficiently.
对我来说,只有第三个有效。
回答by claudio
The only one that works for me is :
唯一对我有用的是:
$jQ('#close_popup').on('click',function(){
$jQ.magnificPopup.proto.close.call(this);
});
回答by Urmas Tassenberg
magnificPopup
iframe:
magnificPopup
框架:
window.parent.$.magnificPopup.close();
回答by NJENGAH
This is the only way I could make the popup close :
这是我可以关闭弹出窗口的唯一方法:
$('body').on( 'click', '#some-div', function( e ) {
e.preventDefault();
$.magnificPopup.close();
});
回答by Rohan Kumar
If you have open the pop up
then it will return an magnific object
,
Using that object
you can call
close method
.
如果你打开了,pop up
那么它会返回一个magnific object
,object
你可以使用它call
close method
。
Try it like,
试试看,
var mgObj=$('your-selecter').magnificPopup({
// you options
});
// code to close pop up on clicking a button
$(document).on('click','button',function(){
if(mgObj)
{
mgObj.close();
}
});