jqModal jQuery 插件 - 如何设置模态弹出窗口的超时?
我正在使用 jQuery 插件 jqModal。
刚接触它,所以我仍在学习它的用法。
我想做的是显示弹出窗口 3 秒钟,然后自动关闭。
基本上,这是我想要的事件流程:
- 我的页面加载。
- 显示模式弹出窗口,显示“正在连接到 MySite..”
- (3 秒后)模式弹出窗口自动关闭。
- 刷新页面(window.location.reload());
这是我到目前为止所拥有的(不多):
HTML:
<div id="jqPopupModal" style="display: none;">Connecting to My Site...</div>
JS:
window.onload = function() {
showPopup();
window.location.reload();
}
function showPopup() {
$('#jqPopupModal').jqm( { modal: true } );
$('#jqPopupModal').jqmShow();
}
是否有一些参数可以传递给 .jqmShow() 函数来设置窗口的超时?或者我应该挂接到 onShow 回调并执行一个简单的 setTimeout 吗?
如果步骤 2 和 4 异步发生也很好:换句话说,页面刷新的同时显示 jQuery 弹出窗口。
有什么想法吗?
编辑:
好的,我已经可以打开/关闭延迟了,但不能使用window.location.reload()
。这么说根本不会发生任何延迟。
这是我的代码:
function fbcPopupOnShow() {{
$('#fbcModalPopup').show();
window.location.reload();
window.setTimeout(new function() {{
$('#fbcModalPopup').jqmHide();
}}, 1000);
}}
function showFacebookConnectPopup() {{
$('#fbcModalPopup').jqm( {{
modal: true,
onShow: fbcPopupOnShow
}});
$('#fbcModalPopup').jqmShow();
}}
我希望 window.location.reload() 能够在显示弹出窗口时重新加载父窗口,而不是其中之一。
编辑2:
发现无法异步重新加载和弹出,因为jqModal弹出窗口并不是真正的“弹出窗口”(即不会生成新窗口)。它只是一个隐藏的DIV。
因此,我刚刚更改了代码以在窗口隐藏后重新加载。
I'm using the jQuery Plugin jqModal.
New to it, so i'm still learning its usage.
What i'm trying to do is show the popup for say 3 seconds, then automatically close.
Basically, here is the flow of events i want:
- My page loads.
- Show modal popup saying "Connecting to MySite.."
- (after 3 seconds) modal popup automatically closes.
- Refresh page (window.location.reload());
Here's what i have so far (it's not much):
HTML:
<div id="jqPopupModal" style="display: none;">Connecting to My Site...</div>
JS:
window.onload = function() {
showPopup();
window.location.reload();
}
function showPopup() {
$('#jqPopupModal').jqm( { modal: true } );
$('#jqPopupModal').jqmShow();
}
Is there some argument i can pass to the .jqmShow() function to set a timeout for the window? Or should i hook into the onShow callback and do a simple setTimeout?
It would also be nice if step 2 and 4 happens asynchronously: in other words, page refreshes whilst jQuery popup is shown.
Any ideas?
EDIT:
Okay so i've got the open/close delay working, but not with the window.location.reload()
. Putting that is causes no delay to happen at all.
Here's my code:
function fbcPopupOnShow() {{
$('#fbcModalPopup').show();
window.location.reload();
window.setTimeout(new function() {{
$('#fbcModalPopup').jqmHide();
}}, 1000);
}}
function showFacebookConnectPopup() {{
$('#fbcModalPopup').jqm( {{
modal: true,
onShow: fbcPopupOnShow
}});
$('#fbcModalPopup').jqmShow();
}}
I was hoping window.location.reload()
would reload the parent window WHILST the popup is being shown, not one or the other.
EDIT 2:
Figured out cant do the reload and popup asynchronously, as the jqModal popup isnt really a "popup" (i.e a new window is NOT spawned). It's just a hidden DIV.
Therefore i've just changed my code to do the reload AFTER the window is hidden.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 onShow 事件在延迟后关闭它(需要 jQuery 1.4+),否则您可以使用 javascript 超时来关闭弹出窗口。
Use the onShow event to close it after a delay (requires jQuery 1.4+), otherwise you can just use javascript timeouts to close the popup.