纯CSS代码实现点击弹出层效果加快网站打开速度

发布时间:2021-01-09 作者:安阳博客网 所属分类:程序代码

虽说JS也可以实线点击弹出层效果,且方法多样化,但对网站加载速度方面确实会有所影响,对于网站优化而言,哪怕网站打开速度慢1毫秒,似乎也就决定了优化的胜败,因此本着能用CSS代码来解决就不用JS来解决的理念,来实现纯CSS代码点击弹出层效果加快网站打开速度!

HTML部分代码

<a href="#open-modal">luck_zhichao</a>
<div id="open-modal" class="modal-window">
<div>
<a href="#" title="Close" class="modal-close"><i class="fa fa-times" aria-hidden="true"></i></a>
<img src="https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png">
</div>
</div>

CSS部分代码

.modal-window {
	position: fixed;
	background-color: rgba(255,255,255,0.25);
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 999;
	visibility: hidden;
	opacity: 0;
	pointer-events: none;
	transition: all .3s
}
.modal-window:target {
	visibility: visible;
	opacity: 1;
	pointer-events: auto
}
.modal-window>div {
	width: 280px;
	position: absolute;
	top: 50%;
	left: 50%;
	-webkit-transform: translate(-50%, -50%);
	transform: translate(-50%, -50%);
	padding: 1em;
	background: #fff;
	border-radius: 10px
}
.modal-window header {
	font-weight: bold
}
.modal-window h1 {
	font-size: 150%;
	margin: 0 0 15px
}
.modal-close {
	line-height: 28px;
	position: absolute;
	right: -18px;
	text-align: center;
	top: -12px;
	text-decoration: none;
	display: block;
	background: black;
	border-radius: 100%;
	height: 30px;
	width: 30px;
	color: #fff
}
.modal-close:hover {
	color: #fff
}