嗨我正在显示一个模式,当人打开我的网站工作正常但是当用户关闭时,模态开放课程不会被删除,不允许他们滚动。
<div id="ageModal" class="modal fade" data-backdrop="static" data-keyboard="false" role="dialog" style="padding-right: 0px;">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" style="background-color: #c9c9f8;" >
<div class="modal-header">
<button type="button" class="close hide" data-dismiss="modal">×</button>
</div>
<div class="modal-body text-center" style="padding-top:10%">
<h1>hi</h1>
<div>
<button type="button" class="btn btn-default" id="ageVerifyYes">Yes</button>
<button type="button" class="btn btn-default" id="ageVerifyNo">No</button>
</div>
<div>
<input type="checkbox" id="rememberMeAge"> Remember Me
</div>
<div id="ageVerifyError" class="hide">
<p class="error-msg">You should agree</p>
</div>
</div>
<div class="modal-footer hide">
<button type="button" class="btn btn-default" data-dismiss="modal">Yes</button>
<button type="button" class="btn btn-default">No</button>
</div>
</div>
</div>
</div>
<style type="text/css">
#ageModal .modal-dialog {
width: 100%;
height: 100%;
margin: 0;
padding: 0px!important;
}
#ageModal .modal-body{
height: 80%;
}
#ageModal .modal-content {
height: 98%;
min-height: 100%;
border-radius: 0;
}
#ageModal .error-msg{
color: #c00;
padding: 10px;
}
.in{
padding:0px!important;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
var isshow = sessionStorage.getItem('isshow');
if (isshow == null || isshow == '') {
sessionStorage.setItem('isshow', 1);
// Show popup here
$('#ageModal').show();
}
else{
//hide popup if opened once
$('#ageModal').hide();
$('.fade').hide();
}
});
$('#ageVerifyNo').on('click', function(){
$('#ageVerifyError').removeClass('hide');
});
$('#ageVerifyYes').on('click', function(){
if($('#rememberMeAge').prop('checked') === true){
setCookie('ageVerified',1,1);
}
$('#ageModal').modal('hide');
$("body").removeClass("modal-open");
});
function setCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
document.cookie = name+'=; Max-Age=-99999999;';
}
如果弹出窗口打开与否,我基本上会在会话中存储。它按预期工作,但即使在模态关闭后,模态打开类仍保留body标签。我确实试过$(&#34; body&#34;)。removeClass(&#34; modal-open&#34;);但没有运气我也创造了另一个,并试图追加到那里,但同样的问题。因为我正在使用cdn
,所以无法编辑引导程序答案 0 :(得分:1)
试试这个
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
答案 1 :(得分:1)
作为替代的快速解决方案,只需从
fade
中删除<div id="ageModal" class="modal fade"...
类。
此问题可能是由于在淡入淡出动画完全完成之前调用了modal('hide')
答案 2 :(得分:0)
您的.show()
和.hide()
应为.modal('show')
和.modal('hide')
答案 3 :(得分:-1)
ngDoCheck(){
var x = $(document).find('.modal.show').length;
if(x>0) {
$('body').addClass('modal-open');
} else {
$('body').removeClass('modal-open');
}
}