当你点击它时,我有一个像门一样打开的方块。我还附加了一个数据属性,它打开了一个模态。所以基本上门打开并显示一个模态。
我想要的是显示动画,打开模态ONCE,然后禁用它。
$(document).on("click", function(){
$('.door_1').addClass('doorOpen');
});
<div class="door_1" id="door_1" data-toggle="modal" data-target="#modal-1"></div>
添加doorOpen类是触发门打开动画的原因。那么有没有办法在初始点击后删除数据属性?
答案 0 :(得分:0)
您可以使用如下所示的setTimeOut创建动画:
$('.door_1').addClass('doorOpen');
setTimeout(function () {
$('#modal-1').modal('hide');
$('.door_1').removeClass('doorOpen');
}, 1000);
这将在1秒或1000毫秒后关闭模态。
答案 1 :(得分:0)
这是如何只打开一次模态的示例..
我们首先在模态上观察事件hidden.bs.modal
,当模态关闭时发生,然后我们只需要从启动模态的按钮中删除data-toggle
attr!
引导模态的所有事件都记录在此处:https://getbootstrap.com/docs/3.3/javascript/#modals-events
// after modal is closed, remove attached events
$('#myModal').on('hidden.bs.modal', function (e) {
$('button').attr('data-toggle', '');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
Some Lorem Ipsum ..
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>