gpt4 book ai didi

javascript - 如何使模式的背景可点击?

转载 作者:太空宇宙 更新时间:2023-11-03 22:59:55 26 4
gpt4 key购买 nike

我想创建一个可以插入网站的聊天框。我一直在使用 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;
}

EXAMPLE

老实说,如果您要对 Bootstrap 模式的功能进行如此大的修改,您还不如使用固定位置的自定义元素,而不是试图对抗 Bootstrap CSS。

关于javascript - 如何使模式的背景可点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36968336/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com