我在动画Modal Windows上遵循了此w3schools教程。现在,我有一个模态窗口,该窗口从顶部滑入并包含一个图像。当我将窗口缩放到比其高时更宽时,图像将随之缩放,并且“模式窗口”的底部从屏幕底部掉落。有没有一种方法可以使窗口动画化,因此无论视口高度如何,窗口始终停在屏幕的中央;第二,将Modal的底部锁定在距视口底部一定的高度吗?
这是我的HTML(JavaScript用图像填充.container):
<div id="modal" class="modal">
<div class="modal-content">
<div id="modal-header" class="modal-header">
<span class="close">×</span>
<h2>Modal Header </h2>
<h3> sub </h3>
</div>
<div class="modal-body">
<div class="container">
</div>
</div>
</div>
这是我的CSS:
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 15vh; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
max-height: 100%;
overflow: hidden;
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.65); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
position: relative;
background-color: #262626;
margin: 0 auto;
border: 1px solid #888;
width: 95%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}
.modal-header {
font-size: 10px;
text-overflow: scale;
padding: 2px 16px;
background-color: black;
color: white;
}
@-webkit-keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
@keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
.modal-body {
padding: 1px 6px;
}
.container img {
width: 100%;
height: auto;
}