【发布时间】:2020-07-07 18:48:00
【问题描述】:
我注意到在使用Bootstrap Modal 时,如果我的模态框内的元素有 CSS 动画,那么这些动画直到模态框显示后才会应用。这实际上很棒,但我无法弄清楚是什么“触发”了动画。更重要的是,如果我关闭模式并重新打开。动画被重置并再次运行。
我很确定这是一个 Bootstrap 的东西,但我找不到任何专门关于这个的文档。
我对此感兴趣的原因是我想通过重新运行动画来利用这一点。如果可能的话,尝试挂钩现有的 Bootstrap 函数是有意义的。 (那个,我只是好奇)
- 这确实是 Bootstrap 的“功能”吗?
- 或者这是一个 CSS 的东西 在元素显示之前不会应用动画?
.animate-box {
width: 100px;
height: 100px;
background: red;
position: relative;
animation-name: example;
animation-duration: 3s;
animation-delay: 0s;
animation-fill-mode: both;
}
@keyframes example {
from {
background-color: yellow;
}
to {
background-color: blue;
}
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalLong">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="animate-box">
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
【问题讨论】:
标签: css twitter-bootstrap css-animations