div遮罩层

news/2024/10/25 9:27:06/

实现遮盖层,使一部分区域不可点击编辑等。

1.简易遮罩层一:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=<device-width>, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>遮罩层(弹窗)</title><style>#cover{ position:absolute;left:0px;top:0px;background:rgba(0, 0, 0, 0.4);width:100%;  /*宽度设置为100%,这样才能使隐藏背景层覆盖原页面*/height:100%;filter:alpha(opacity=60);  /*设置透明度为60%*/opacity:0.6;  /*非IE浏览器下设置透明度为60%*/display:none; z-Index:1;  }#modal{ position:absolute;width:500px;height:300px;top:50%;left:50%;background-color:#fff;display:none;cursor:pointer;z-Index:2;  }</style>
</head>
<body><div>显示页面的全部内容<div id="opens">打开弹框</div></div><!-- //页面的遮罩层 --><div id="cover"></div><!-- //页面的弹出框 --><div id="modal"><div id="closes">关闭弹框</div></div><script>var opens = document.querySelector("#opens");var closes = document.querySelector("#closes");var cover = document.querySelector("#cover");var modal = document.querySelector("#modal");opens.onclick = function(){cover.style.display="block";   //显示遮罩层modal.style.display="block";   //显示弹出层};closes.onclick = function(){cover.style.display="none";   //隐藏遮罩层modal.style.display="none";   //隐藏弹出层};</script>
</body>
</html>

结果:

2.div遮罩层二:

可通过点击实现遮罩层,改变div背景色,宽高: 

  •  专门写一个div(没有任何内容)做遮罩层,通过绝对定位的层级实现遮罩;
  • 宽度高度设置为100%,这样才能使隐藏背景层覆盖原页面。
  • 设置透明度为0.3;
  • (兼容IE)非IE浏览器下设置透明度为30;
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=<device-width>, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>揉捏DIV</title><style>ul,li { margin:0; padding: 0; }#wrap { position: absolute; z-index: 1;}h1 { display: inline; } .set_btn { background: red; border: none; width:100px; height: 30px; color: white; font-size: 16px; }#box { width:100px; height: 100px; border: 4px solid black; margin-top: 10px; background: white; }   /* 专门写一个div做遮罩层,通过绝对定位的层级实现遮罩 *//*宽度设置为100%,这样才能使隐藏背景层覆盖原页面*/ /*设置透明度为60%*//*非IE浏览器下设置透明度为60%*/#cover { position:absolute; left:0px; top:0px; background:#747374; width:100%; height:100%; filter:alpha(opacity=60); opacity:0.3; display:none; z-index:1; }#mask { display: none; width:300px; height: 240px; background: white; border: 10px solid gainsboro; position: absolute; z-index: 2; left:40%; top:40%; }#mask ul { width:300px; height: 180px; padding-top: 10px; }#mask li { list-style: none; height: 60px; padding-left: 10px; }#mask label { display: inline-block; width: 120px; }#mask span { display: inline-block; width: 40px; height: 40px; line-height: 40px; background: gainsboro; text-align: center; border: 1px solid gray;  } #mask .title .red { background: red; }#mask .title .yellow { background: yellow; }#mask .title .blue { background: blue; }#mask input { background: #3f379e; border: none; color: white; width: 50px; height: 20px; text-align: center; }#mask .btn_div { margin: 0 auto; width: 106px;}</style>
</head>
<body><div id="wrap"><h1>请为下面DIV设置样式:</h1><!-- <input class="set_btn" type="button" value="点击设置"/> --><button class="set_btn">点击设置</button><div id="box"></div></div><div id="cover"></div><div id="mask"><ul><li class="title"><label>请选择背景色:</label><span class="red">红</span><span class="yellow">黄</span><span class="blue">蓝</span></li><li><label>请选择宽(px):</label><span class="w200">200</span><span class="w300">300</span><span class="w400">400</span></li><li><label>请选择高(px):</label><span class="h200">200</span><span class="h300">300</span><span class="h400">400</span></li>    </ul><div class="btn_div"><input class="reset_btn" type="button" value="恢复"/><input class="fix_btn" type="button" value="确定"/></div>
</div><script>//弹出遮罩层var cover = document.querySelector("#cover");var set_btn = document.querySelector(".set_btn");var mask = document.querySelector("#mask");var box = document.querySelector("#box");set_btn.onclick = function(){cover.style.display="block";//弹出层mask.style.display="block";//弹出窗};//隐藏遮罩层var reset_btn = document.querySelector(".reset_btn");var fix_btn = document.querySelector(".fix_btn");reset_btn.onclick = function(){cover.style.display="none";//弹出层mask.style.display="none";//弹出窗box.style.cssText = "width:100px; height: 100px; border: 4px solid black; margin-top: 10px; background: white; ";};fix_btn.onclick = function(){cover.style.display="none";//弹出层mask.style.display="none";//弹出窗};//点击红黄蓝更改box背景色var red = document.querySelector(".red");var yellow = document.querySelector(".yellow");var blue = document.querySelector(".blue");red.onclick = function(){box.style.background = "red";};yellow.onclick = function(){box.style.background = "yellow";};blue.onclick = function(){box.style.background = "blue";};//点击宽高对应更改box宽高var w200 = document.querySelector(".w200");var w300 = document.querySelector(".w300");var w400 = document.querySelector(".w400");var h200 = document.querySelector(".h200");var h300 = document.querySelector(".h300");var h400 = document.querySelector(".h400");w200.onclick = function(){box.style.width = "200px";};w300.onclick = function(){box.style.width = "300px";};w400.onclick = function(){box.style.width = "400px";};h200.onclick = function(){box.style.height = "200px";};h300.onclick = function(){box.style.height = "300px";};h400.onclick = function(){box.style.height = "400px";};</script>
</body>
</html>

结果:


http://www.ppmy.cn/news/170935.html

相关文章

css系列----纯 css 实现轮播图(手动)

2、纯 css 实现轮播图(手动) 实现原理&#xff1a;利用 css3 中 input:checked 和 &#xff5e;选择器实现 /* 设置容器大小*/ .container {position: relative;width: 800px;height: 300px; } /* 设置input位置 */ .container input {position: absolute;z-index: 23;botto…

DEF解析

DEF 全称Design Exchange Format, 用于电路物理信息交互&#xff0c;是将数字实现前后端连接起来的桥梁。目前常用的DEF version 是5.8, 在DEF 中可以定义如下信息&#xff0c;本文不解析每一部分的含义&#xff0c;只概述做物理综合需要的部分信息。DEF file 有如下限定&#…

H323——H239演示功能

1. 概述 H239在ITU文档中实际命名为Role management and additional media channels for ITU-T H.300-series terminals&#xff0c;意为H300系列中断的角色管理和额外没媒体流&#xff0c;H239是H323中用来开启辅流的信令流程规范&#xff0c;会为相关的媒体流添加角色&#…

css系列----纯 css 实现轮播图(自动)

3、纯 css 实现轮播图(自动) 实现原理&#xff1a;利用 css3 中 动画和 overflow:hidden 实现 /* 容器大小 */ .container {height: 300px;width: 800px;overflow: hidden; }/* .wrap */ .wrap {position: relative;left: 0px;width: 2400px;animation: animateImg ease 5s i…

虹科分享 | 近距离接触最新的3个勒索软件

上一期内容为大家讲解了遇到勒索软件时支付或不支付赎金的利弊&#xff0c;以及如何利用Datalocker的产品来防止基于USB的威胁进入你的网络。本期小编将带大家了解当今最新的3个勒索软件&#xff0c;以及Datalocker是如何在这之中起到作用的。了解更多内容&#xff0c;敬请阅读…

虹科分享 | 数据泄露的剖析

数据泄露的剖析 数据泄露是什么&#xff0c;当你发现它们时该怎么做&#xff1f; 可以说&#xff0c;在过去的24个月里&#xff0c;没有哪个词比 "数据泄露 "这个词更能主宰科技界了。在过去的两年里&#xff0c;网络安全事故的头条新闻已经饱和&#xff0c;从影响…

虹科分享 | 如何确保工作场所的网络安全?给您保持企业安全的44个提示

在过去的几年里&#xff0c;对各种规模的企业来说&#xff0c;保持信息的安全和保障是一个挑战。从现场到网上再到混合工作场所的快速转变迫使企业改变&#xff0c;或至少重新审视他们的网络安全做法和协议&#xff1b;他们往往没有做好准备。事实上&#xff0c;根据CyberEdge的…

十条ChatGPT常用的Prompt

Prompt 本文数据来源&#xff1a;Will 3.6-6.16 硅谷&#xff0c;原作者&#xff1a;rowancheung 一&#xff0c;简化复杂的信息 Prompt&#xff1a; 将&#xff08;主题&#xff09;分解成更小、更容易理解的部分。使用类比和现实生活中的例子来简化概念并使其更相关 Brea…