弹出最简单的模式化遮罩层的js代码

时间:2024-06-18 16:48:53 

假设我们有一个容器container如下:


<style type=”text/css”>
#container{width:auto;height:auto; overflow:hidden;}
/*这里的overflow:hidden;属性主要是为了设置使超出container的部分自动隐藏,之所以设置这个属性,是为了解决ie8及以下版本浏览器兼容性问题*/
</style>
<div id=”container” >
</div>



现在要在网页中弹出一个div层,使在关闭弹出的div层之前不可操作container。
那么,我们首先需要定义出这个遮罩的div层如下:


<div id=”continer”>
<!—只所以将遮罩层放到container里面
<divid=”shade” style=”width:1600px;height:900px;/*给遮罩层一个初始大小*/”>
<input name=”close” id=”close” value=”关闭”>
</div>
</div>


接下来,就是用js来使遮罩层始终显示在屏幕上并不可操作遮罩层下面的内容,点击关闭按钮关闭遮罩层


<script type=”text/javascript”>
$(function(){
//获取当前浏览器的内部宽和高
varnWidth = window.innerWidth;
varnHeight = window.innerHeight;
//设置遮罩层的宽和高
$("#shade").width(nWidth);
$("#shade").height(nHeight);
//设置关闭按钮居中显示
$("#close").css("margin-top",nHeight/2-50+"px");
//设置当浏览器大小改变时触发的事件
$(window).resize(function(){
//获取当前浏览器的内部宽和高
varnWidth = window.innerWidth;
varnHeight = window.innerHeight;
//设置遮罩层的宽和高
$("#shade").width(nWidth);
$("#shade").height(nHeight);
//设置关闭按钮居中显示
$("#putPwd").css("margin-top",nHeight/2-50+"px");
});
//设置关闭按钮消除遮罩层
$("#close").click(function(){
$("#shade").removeAttr("id");
$("#shade").html("");
});
//也可用纯js来写
Document.getElementById(“shade”).style…….;
//后面多说无益,如果有兴趣又实在不会写,可以和本人联系。
})
</script>
标签:弹出,模式化,遮罩层
0
投稿

猜你喜欢

  • python如何操作mysql

    2024-01-16 23:27:28
  • Python连接Hadoop数据中遇到的各种坑(汇总)

    2023-09-13 20:16:34
  • python通过elixir包操作mysql数据库实例代码

    2024-01-26 04:12:16
  • python 读取Linux服务器上的文件方法

    2023-03-31 23:54:19
  • 慎用 script 节点的 src 属性来传递参数

    2009-11-18 12:59:00
  • python数据处理详情

    2021-05-08 12:53:12
  • pytorch分类模型绘制混淆矩阵以及可视化详解

    2023-01-17 17:35:43
  • python判断给定的字符串是否是有效日期的方法

    2023-04-07 20:07:07
  • OpenCV中图像通道操作的深入讲解

    2022-02-13 02:39:22
  • 如何配置关联Python 解释器 Anaconda的教程(图解)

    2021-06-13 15:27:30
  • 学习ASP和编程的28个观点

    2008-06-27 12:57:00
  • asp如何设置cookie的过期时间

    2008-02-29 13:36:00
  • 关于python爬虫应用urllib库作用分析

    2023-11-02 12:59:43
  • Python3实现的反转单链表算法示例

    2021-09-22 01:33:30
  • Go定时器cron的使用详解

    2024-04-28 10:47:43
  • 极致之美——百行代码实现全新智能语言Lisp

    2010-07-13 13:07:00
  • 网页中空格的烦恼

    2011-04-28 09:26:00
  • SQL Server主键约束(PRIMARY KEY)

    2024-01-24 04:46:56
  • CentOS6.9+Mysql5.7.18源码安装详细教程

    2024-01-19 02:42:14
  • Python新手学习raise用法

    2021-01-08 22:37:52
  • asp之家 网络编程 m.aspxhome.com