我想制作一个覆盖整个页面的div.我把高度为100%的css风格但是这只覆盖了可视区域.当我向下滚动时,我希望它也覆盖该区域.
Gab*_*oli 81
使用position:fixed这种方式你的div将持续在整个可视区域.
给你的div一个类,overlay并在你的CSS中创建以下规则
.overlay{
opacity:0.8;
background-color:#ccc;
position:fixed;
width:100%;
height:100%;
top:0px;
left:0px;
z-index:1000;
}
Run Code Online (Sandbox Code Playgroud)
演示:http://www.jsfiddle.net/TtL7R/1/
以下css将完成所需的工作。
.overlay {
background: #fff;
position: fixed;
bottom: 0;
right: 0;
left: 0;
top: 0;
}
Run Code Online (Sandbox Code Playgroud)
有时我们想用覆盖层覆盖页面主体,直到网页的所有资源没有完全下载。然后我们淡出此覆盖层以显示网页的完整内容。下面的例子是对上面答案的一点修改,在这个例子中,我们展示了一个覆盖整个页面的CSS3动画覆盖层:
更多动画请访问这里
.overlay {
background: #fff;
position: fixed;
bottom: 0;
right: 0;
left: 0;
top: 0;
}
Run Code Online (Sandbox Code Playgroud)
$(window).load(function() {
$('.overlay').delay(1000).fadeOut(800);
});Run Code Online (Sandbox Code Playgroud)
.overlay {
background: #fff;
position: fixed;
bottom: 0;
right: 0;
left: 0;
top: 0;
}
.loading {
position: absolute;
top: 50%;
left: 50%;
}
.loading-bar {
display: inline-block;
width: 4px;
height: 18px;
border-radius: 4px;
animation: loading 1s ease-in-out infinite;
}
.loading-bar:nth-child(1) {
background-color: #3498db;
animation-delay: 0;
}
.loading-bar:nth-child(2) {
background-color: #c0392b;
animation-delay: 0.09s;
}
.loading-bar:nth-child(3) {
background-color: #f1c40f;
animation-delay: .18s;
}
.loading-bar:nth-child(4) {
background-color: #27ae60;
animation-delay: .27s;
}
@keyframes loading {
0% {
transform: scale(1);
}
20% {
transform: scale(1, 2.2);
}
40% {
transform: scale(1);
}
}Run Code Online (Sandbox Code Playgroud)