如何使模态的背景可以单击
How do I make the background of a modal clickable?
我想创建一个可以插入网站的聊天框。我一直在使用Bootstrap Modal来实现这一点。
我希望当用户在模态之外单击时,我的模态不会关闭。但网站背景应该仍然是可点击/可选择的,这样用户仍然可以在网站上执行操作。
这是我迄今为止编写的代码。
$(window).load(function () {
$('#myModal').modal({ backdrop: 'static', keyboard: false});
$('#myModal').modal('show');
});
function myFunction() {
$('#myModal').modal('toggle');
window.alert('Hello');
}
.vertical-alignment-helper {
display:table;
height: 100%;
width: 100%;
pointer-events:none; /* This makes sure that we can still click outside of the modal to close it */
}
.vertical-align-center {
/* To center vertically */
display: table-cell;
vertical-align: middle;
pointer-events:none;
}
.modal-content {
/* Bootstrap sets the size of the modal in the modal-dialog class, we need to inherit it */
width:inherit;
height:inherit;
/* To center horizontally */
margin: 0 auto;
pointer-events: all;
float: left;
max-width: 250px;
background-color: #ffffff;
}
.textarea-nonresizable {
height: 10em;
border-radius: 1em;
outline: none; /* removes the default outline */
resize: none; /* prevents the user-resizing, adjust to taste */
}
.header-cl {
background-color: #262626;
color: #FFFFFF;
border-bottom-width: 0px;
}
.header-f {
font-size: 14px;
font-weight: bold;
}
.body-cl {
background-color: #c7c8c9;
}
.foot-cl {
border-top-width: 0px;
padding-top: 0px;
background-color: #c7c8c9;
color: #FFFFFF;
}
.btn-ft {
background-color: #3f1603;
color: #FFFFFF;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active, .btn-primary.active, .open>.dropdown-toggle.btn-primary {
color: #FFFFFF;
background-color: #3f1603;
}
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="modal fade " id="myModal" role="dialog">
<div class="vertical-alignment-helper">
<div class="modal-dialog vertical-align-center modal-sm">
<div class="modal-content">
<div class="modal-header header-cl">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span class="glyphicon glyphicon-minus-sign"></span>
</button>
<h4 class="modal-title header-f">Contact Us</h4>
</div>
<div class="modal-body body-cl">
<textarea class="form-control textarea-nonresizable" id="comment" placeholder="Type your message here"></textarea>
</div>
<div class="modal-footer foot-cl">
<div style="float:left;color:#FFFFFF;font-size: 11px;line-height: 34px;">
Powered by <strong>Stackoverflow</strong> </div>
<button type="button" class="btn btn-primary btn-ft" onclick="myFunction()">Start Text</button>
</div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
您可以在.modal
和.modal-backdrop
上使用pointer-events: none;
。或者用display: none;
隐藏.modal-backdrop
.modal {
pointer-events: none;
}
.modal-backdrop {
display: none;
}
示例
老实说,如果你要修改引导模式的功能这么多,你还不如使用一个固定位置的自定义元素,而不是试图对抗引导CSS。
相关文章:
- Javascript对象类在单击时打开窗口进行颜色选择,并在更改时替换对象背景颜色
- 如何在显示侧边栏时禁用背景,单击除侧边栏之外的任何位置都会关闭侧边栏
- 获取表中要更改的行的背景以进行单击
- 如何创建背景图像列表'URL,并使用jQuery在单击函数时应用它们
- 如何使模态的背景可以单击
- 谷歌工作表中的按钮,当单击时,会更改特定单元格的背景
- 使用 jQuery 单击链接时更改链接背景颜色
- 在按钮单击时将图像URL数据显示到弹出框中,而无需禁用背景
- 如何使用Kango框架在弹出框中单击按钮时更改网站的背景
- 通过右键单击更改完整日历中事件的背景颜色 - 不起作用
- 尝试在单击时使用Jquery更改html的背景颜色
- 单击时背景淡入
- on单击“更改背景图像”
- 使用jQuery单击时更改背景颜色
- 单击背景时使用鼠标向下制作动画
- 为什么当用户单击背景时,我的jQuery Mobile页脚会出现然后消失
- 淡入淡出灯箱,然后单击背景,使其消失
- 淡出JavaScript”;模式窗口”;当单击背景时
- 通过单击背景来消除html对话框元素
- 通过单击背景关闭叠加层