我想用 JavaScript 显示和隐藏一个 div。有人有额外的代码吗?到目前为止,这是我的代码:
<script>
window.onload=function(){$hide.div(div)};
</script>
HTML:
<div class="overlay"></div>
<div class="modal">I'm the modal window!</div>
CSS:
.overlay {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: rgba(0,0,0,0.5);
z-index: 10;
}
.modal {
width: 300px;
height: 200px;
line-height: 200px;
position: fixed;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -150px;
background-color: #f1c40f;
border-radius: 5px;
text-align: center;
z-index: 11;
}