打开第二个 fancybox 在另一个 fancybox 中!
嘿!我的花式盒子遇到了麻烦!
我正在一个 fancybox 中启动一个表单。通常,它由 fancybox 以 iframe 模式打开(因为它是从其他域作为小部件启动的)。在此 iframe 中,我打开第二个 fancybox 来显示验证错误。 所有这些 - 效果都很好。
但是,如果用户访问表单的 url - 我需要将表单显示在使用 type:inline 调用表单的 fancybox 中。这是第二个 fancybox 失败的地方,它没有弹出,而是替换了父 fancybox - 并且我的表单消失了。
那么...如何启动 fancybox 的多个实例?
Hey! I'm having trouble with my fancyboxes!
I am launching a form within a fancybox. Normally, its opened by fancybox in a iframe mode (since it's being launched as a widget from other domains). Within this iframe, i am opening a second fancybox to display validation errors. All this - works good.
But, if a user visists the url to the form - i need the form to be displayed within a fancybox thats calling the form with type:inline. This is where the second fancybox fails, instead of popping out, over the parent fancybox, it replaces it - and my form disappears.
So... how do i launch multiple instances of fancybox?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
坏消息是,fancybox 是一个单实例脚本。页面加载时,它会创建所有覆盖 DIV。所有与 fancybox 绑定的链接和其他元素都将重新使用这些覆盖层。让 fancybox 处理多个实例将需要对脚本进行或多或少的更大覆盖。
The bad news is, fancybox is a single-instance script. On page load it creates all overlay DIVs. All links and other elements bound with fancybox will just re-use these overlays. Making fancybox handle multiple instances would require a more or less bigger overwrite of the script.
我通过使用 afterClose 并重新打开我之前的 fancybox 来实现此目的
。当您关闭模态 2 并重新打开模态 1 时,该事件会触发。
I achieved this by using afterClose, and re-opening my previous fancybox
This fires when you close modal 2 and it re-opens modal 1.
从可用性和设计的角度来看,您甚至不应该尝试这样做,因为这肯定会造成可怕的用户体验。这就是为什么大多数模态框框架不支持它的原因。
一般来说,当您遇到不支持的东西时,无论是浏览器还是知名库,请停下来思考是否有缺少支持的原因,并且通常您会意识到缺少支持支持是设计使然。
From a usability and design perspective you should never even attempt this, since it is a sure fire way of creating a horrible user experience. This is why most modal box frameworks do not support it.
In general when you run in to things that are not supported, whether this be by the browser or by a well known library, stop and think if there is a reason for the missing support, and more often than not you will realize that the missing support is by design.
我已经通过使用
beforeClose
回调成功做到了这一点。基本上,在窗口关闭之前,设置一个超时函数来打开另一个窗口,并在回调中返回 false 以防止 Fancybox 关闭窗口。
I've managed to do this by using the
beforeClose
callback.Basically, before the window closes, set a timeout function to open the other window and return false in the callback to prevent Fancybox from closing the window.
如果您使用 iframe 打开第一个 fancybox,则可以实现此目的:
You can achieve this if you open first fancybox with iframe: