如何以编程方式关闭打开的 jquery.reveal.js 模式框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4884369/
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 do I programmatically close an open jquery.reveal.js modal box?
提问by TJ McKenzie
I am using the Reveal jQuery plugin. http://www.zurb.com/playground/reveal-modal-plugin
我正在使用 Reveal jQuery 插件。 http://www.zurb.com/playground/reveal-modal-plugin
I need to programmatically close the model box when I am done with it, however that feature is not including directly with the plugin.
完成后,我需要以编程方式关闭模型框,但是该功能不直接包含在插件中。
According to Dave in the comments page,
根据 Dave 在评论页面中的说法,
"The code is in there, just need to hook it up to be called programmatically."
“代码就在那里,只需要将其连接起来以编程方式调用即可。”
回答by Silas Snider
If your modal's id is 'reveal-modal', then just this line will do it:
如果你的模态的 id 是 'reveal-modal',那么这一行就可以做到:
$('#reveal-modal').trigger('reveal:close');
回答by Cory
You can do it a couple of ways.
你可以通过几种方式做到这一点。
Trigger a click via jquery on the dismissmodalclass element (defaults to 'close-reveal-modal')
通过jquery在dismissmodalclass元素上触发点击(默认为'close-reveal-modal')
$('.close-reveal-modal').click();
OR
或者
Add this to reveal.js
将此添加到reveal.js
$.fn.hideModal = function(options){
var self = this,
modal = $(self),
topMeasure = parseInt(modal.css('top'));
$('.reveal-modal-bg').css({'display' : 'none'});
modal.css({'visibility' : 'hidden', 'top' : topMeasure});
}
and use
并使用
$('#your_modal_box').hideModal()
回答by Paul Millsaps
The modals class is usually 'reveal-modal'. so changing the lookup to be class based rather than id based, makes this work for more cases:
modals 类通常是“reveal-modal”。因此,将查找更改为基于类而不是基于 id,可以在更多情况下使用:
$('.reveal-modal').trigger('reveal:close');
回答by Anil
This code works for me: $('#reveal-modal').trigger('reveal:close');
这段代码对我有用: $('#reveal-modal').trigger('reveal:close');
I had a zip text field and a buttom which was opening another pop up
我有一个 zip 文本字段和一个正在打开另一个弹出窗口的按钮
回答by vidalsasoon
$('#your_modal_box').foundation('reveal', 'close');
$('#your_modal_box').foundation('reveal', 'close');
works for zurb foundation
为 zurb 基金会工作
回答by vivekj011
You can do that while registering your reveal div/element.
您可以在注册显示 div/元素时执行此操作。
suppose, [reveal-div] you are registering for reveal. And suppose you have one button/div [close-reveal] onclick of which you want to close your reveal. Then pass [close-reveal] as [dismissModalClass] as shown below.
假设,[reveal-div] 您正在注册揭示。并且假设您有一个按钮/div [close-reveal] onclick 想要关闭您的展示。然后将 [close-reveal] 作为 [dismissModalClass] 传递,如下所示。
$('.reveal-div').reveal({
dismissModalClass : "close-reveal"
});
回答by user2002018
I discovered a bug in older foundation/reveal library when calling 'reveal:close' event second time after dialog was hidden and shown again - doesn't work. After hours of debugging I found the following CSS hack which force-hides the modal: $("#reveal-modal")[0].style.cssText = "visibility: hidden;"
在隐藏并再次显示对话框后第二次调用 'reveal:close' 事件时,我在旧的基础/显示库中发现了一个错误 - 不起作用。经过数小时的调试,我发现了以下 CSS hack,它强制隐藏了模态: $("#reveal-modal")[0].style.cssText = "visibility: hidden;"