请问怎么让html页面固定住。失去滚动条啊。这是苹果页面的一个效果。按了放大镜屏幕就固定住了。
width: 100%;
display: none;
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
height: 100%;
z-index: 9999;
background: rgba(0,0,0,.4);
我把整个灰色的背景写了这个css。没啥用。。
请问怎么让html页面固定住。失去滚动条啊。这是苹果页面的一个效果。按了放大镜屏幕就固定住了。
width: 100%;
display: none;
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
height: 100%;
z-index: 9999;
background: rgba(0,0,0,.4);
我把整个灰色的背景写了这个css。没啥用。。
写个简单的小demo
关键点是设置html中body的overflow属性为hidden
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.header{
width: 100%;
height: 100px;
background-color: green;
display: flex;
justify-content: center;
align-items: center;
}
.main{
background-color: yellow;
width: 100%;
height: 1200px;
}
input{
width: 400px;
height: 30px;
}
.hiddenDiv{
height: 100%;
width: 100%;
position: absolute;
background-color: black;
opacity: .3;
display: none;
}
</style>
</head>
<body>
<div class="header">
<input type="text" placeholder="请输入你的值" id='inputDom' >
</div>
<div class="main">
<div class="hiddenDiv"></div>
</div>
<script>
document.getElementById("inputDom").addEventListener("click",function(){
//设置页面的滚动为hidden
document.body.style.overflow = "hidden";
//灰色区域出现
document.getElementsByClassName('hiddenDiv')[0].style.display = 'block';
})
</script>
</body>
</html>
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
3 回答5.1k 阅读✓ 已解决
5 回答2k 阅读
针对整个页面的滚动条:
如果是页面内的某个元素产生了滚动条: