我有纯css弹出这个弹出工作onclick按钮但我需要在页面加载完成时弹出这个div
<div class="wrap">
<a href="#modal-one" class="btn btn-big">Modal!</a>
</div>
<!-- Modal -->
<div class="modal" id="modal-one" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-header">
<h2>Modal in CSS?</h2>
<a href="#" class="btn-close" aria-hidden="true">×</a>
</div>
<div class="modal-body">
<p>One modal example here! :D</p>
</div>
<div class="modal-footer">
<a href="#" class="btn">Nice!</a>
</div>
</div>
</div>
加载页面时我需要自动弹出此窗口,然后单击
弹出第二个选项可以帮助我一些人
答案 0 :(得分:1)
一种选择是使用javascript并为新类添加额外规则。
的CSS:
.modal:target:before, .modal.loaded:before { ... }
.modal:target .modal-dialog, .modal.loaded .modal-dialog { ... }
JS:
$( document ).ready( function() {
$('.modal').addClass('loaded');
$('.btn-close, .btn').click( function() {
$('.modal').removeClass('loaded');
});
});
小提琴:http://jsfiddle.net/ycc7anhy/2/
仅限css解决方案是:target
url关闭弹出窗口。
.modal:target:before {
display: none;
}
.modal:before {
content:"";
display: block;
background: rgba(0, 0, 0, 0.6);
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
}
.modal .modal-dialog {
background: #fefefe;
border: #333333 solid 1px;
border-radius: 5px;
margin-left: -200px;
position: fixed;
left: 50%;
z-index: 11;
width: 360px;
-webkit-transform: translate(0, 0);
-ms-transform: translate(0, 0);
transform: translate(0, 0);
-webkit-transition: -webkit-transform 0.3s ease-out;
-moz-transition: -moz-transform 0.3s ease-out;
-o-transition: -o-transform 0.3s ease-out;
transition: transform 0.3s ease-out;
top: 20%;
}
.modal:target .modal-dialog {
top: -100%;
-webkit-transform: translate(0, -500%);
-ms-transform: translate(0, -500%);
transform: translate(0, -500%);
}