在弹出元素外部单击时关闭bPopup
Close bPopup when clicking outside the popup element
我的页面上有一个使用bPopup的弹出div(http://dinbror.dk/blog/bpopup/)插入,一切都很好,但我希望当用户使用鼠标点击时,或者在弹出分区之外的移动触摸时,弹出窗口关闭。
我已经尝试使用这里建议的一些解决方案,并查看了bPopup文档,但似乎无法使其发挥作用。
这是HTML:
<div id="phone-pop">
<table>
<tr>
<td>Head Office:</td>
<td class="right">00000 000 000</td>
</tr>
<tr>
<td>Offroad Mobile:</td>
<td class="right">00000 000 000</td>
</tr>
<tr>
<td>F3 Mobile:</td>
<td class="right">00000 000 000</td>
</tr>
</table>
<span class="button b-close"><img src="img/close.svg"></span>
</div>
<div id="email-pop">
<table>
<tr>
<td>Name:</td>
<td class="right">Please enter your name.</td>
</tr>
<tr>
<td>Email:</td>
<td class="right">Please enter your email address.</td>
</tr>
<tr>
<td>Message:</td>
<td class="right">Please enter your message for us.</td>
</tr>
</table>
<span class="button b-close"><img src="img/close.svg"></span>
</div>
<div id="fb-pop">
<div class="fb-page">Facebook Page Stream Here</div>
<span class="button b-close"><img src="img/close.svg"></span>
</div>
这是javascript:
;(function($) {
$(function() {
$('#phone').bind('click', function(e) {
e.preventDefault();
$('#phone-pop').bPopup({
appendTo: 'form'
, zIndex: 2
, easing: ('linear')
, escClose: true
, transitionClose: true
});
});
});
$(function() {
$('#email').bind('click', function(e) {
e.preventDefault();
$('#email-pop').bPopup({
appendTo: 'form'
, zIndex: 2
, easing: ('linear')
, escClose: true
, transitionClose: true
});
});
});
$(function() {
$('#fb').bind('click', function(e) {
e.preventDefault();
$('#fb-pop').bPopup({
appendTo: 'form'
, zIndex: 2
, easing: ('linear')
, escClose: true
, transitionClose: true
});
});
});
})(jQuery);
提前感谢您的帮助。
演示页面上的技巧http://dinbror.dk/bpopup/很简单。他们使用另一个具有css属性的div
z-index:9998;
并且弹出窗口具有
z-index:9999;
div的代码是
<div class="b-modal __b-popup1__" style="position: fixed; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.7; z-index: 9998; cursor: pointer; background-color: rgb(0, 0, 0);"></div>
那么你只需要一点javascript
jquery示例:
$('.b-modal').click(function(){
$('#my-modal').hide();
});
相关文章:
- 使用clickToggle并在单击另一个元素时关闭元素
- 单击时将焦点更改为元素
- 单击F5时如何停止页面加载
- 通过单击表单中的按钮,在代码生成中使用javascript生成字母数字代码
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 单击jquery清除输入值
- 单击按钮以等待单击按钮
- 在单击href链接的同时下载文件
- 单击顶部导航时如何进行向下滚动效果(向下滑动).
- 使图像在单击时展开到不大于浏览器
- 单击按钮后如何逐个调用分区,上一个分区将隐藏
- 如何在单击复选框后调用控制器方法
- 单击页面上的链接后高度发生变化
- 使用jquery在单击时在单元格中输入值
- 将纯文本URL转换为可单击链接
- ASP.NET通过单击JavaScript按钮触发c#事件
- 单击更改图标并通过javascript添加一个css类
- 阻止在select2单击时调用ajax
- 复制图像路径以单击它
- 在弹出元素外部单击时关闭bPopup