JavaScript实现的弹出遮罩层特效经典示例【基于jQuery】


Posted in jQuery onJuly 10, 2019

本文实例讲述了JavaScript实现的弹出遮罩层特效。分享给大家供大家参考,具体如下:

这篇给大家分享一个简单的遮罩层特效,先上效果图。

JavaScript实现的弹出遮罩层特效经典示例【基于jQuery】

代码:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>查看,修改,删除</title>
  <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
  <style>
    table{
      width:500px;
      border:1px solid blue;
      border-collapse: collapse;
    }
    table th{
      border:1px solid blue;
      height:30px;
    }
    table td{
      border:1px solid blue;
      text-align:center;
      height:30px;
    }
    table td a {
      color:red;
    }
    div.proDiv{
      width:500px;
      position: absolute;
      left:50%;
      margin-left:-250px;
      padding:10px;
      border:1px solid red;
      top:100px;
      background: #fff;
      display: none;
      z-index: 3
    }
    div.proDiv p{
      border-bottom:1px solid red;
    }
    div.proDiv a.close{
      color:red;
    }
  </style>
</head>
<body>
  <table>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
      <th>工作</th>
      <th>工资</th>
      <th>操作</th>
    </tr>
    <tr>
      <td>张三</td>
      <td>22</td>
      <td>项目经理</td>
      <td>12000</td>
      <td>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="view">查看</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >修改</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="del">删除</a>
      </td>
    </tr>
    <tr>
      <td>李四</td>
      <td>24</td>
      <td>前端工程师</td>
      <td>10000</td>
      <td>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="view">查看</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >修改</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="del">删除</a>
      </td>
    </tr>
    <tr>
      <td>王五</td>
      <td>21</td>
      <td>java工程师</td>
      <td>12000</td>
      <td>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="view">查看</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >修改</a>
        <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="del">删除</a>
      </td>
    </tr>
  </table>
  <div class="proDiv">
    <p><strong>姓名:</strong><span></span></p>
    <p><strong>年龄:</strong><span></span></p>
    <p><strong>工作:</strong><span></span></p>
    <p><strong>工资:</strong><span></span></p>
    <a class="close" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >关闭</a>
  </div>
</body>
<script>
  //查看操作
  $('a.view').click(function(){
    //获取文档的宽和高
    var maskWidth = $(document).width();
    var maskHeight = $(document).height();
    //遮罩层初始化
    $('<div class="mask"></div>').appendTo($('body'));
    $('div.mask').css({
      'position':'absolute',
      'top':0,
      'left':0,
      'background':'black',
      'opacity':0.5,
      'width':maskWidth,
      'height':maskHeight,
      'z-index':2
    });
    var data = [];//保存数据的数组
    //将一行的数据添加到数据中
    $(this).parent().siblings().each(function(){
      data.push($(this).text())
    });
    //将内容显示到弹出层中
    $('div.proDiv').children().each(function(i){
      $(this).children('span').text(data[i]);
    });
    $('div.proDiv').show();//显示弹出层
    //关闭操作
    $('a.close').click(function(){
      $(this).parent().hide();
      $('div.mask').remove();
    });
  });
  //删除操作
  $('a.del').click(function(){
    $(this).parents('tr').remove();
  });
</script>
</html>

页面中有一个表格,一个隐藏的弹出层,当点击查看按钮,首先创建一个遮罩层,然后获取这一行中的数据,并把数据显示到弹出层中,最后把弹出层隐藏,点击关闭按钮关闭弹出层并关闭遮罩层。点击删除按钮把这个tr删除即可。

感兴趣的朋友可以使用在线HTML/CSS/JavaScript代码运行工具:http://tools.3water.com/code/HtmlJsRun测试上述代码运行效果。

更多关于jQuery相关内容可查看本站专题:《jQuery页面元素操作技巧汇总》、《jQuery常见事件用法与技巧总结》、《jQuery常用插件及用法总结》、《jQuery扩展技巧总结》及《jquery选择器用法总结》

希望本文所述对大家jQuery程序设计有所帮助。

jQuery 相关文章推荐
jQuery插件Echarts实现的渐变色柱状图
Mar 23 jQuery
jquery实现图片上传前本地预览
Apr 28 jQuery
jquery图片放大镜效果
Jun 23 jQuery
jQuery简介_动力节点Java学院整理
Jul 04 jQuery
一个有意思的鼠标点击文字特效jquery代码
Sep 23 jQuery
jquery-file-upload 文件上传带进度条效果
Nov 21 jQuery
利用jquery如何从json中读取数据追加到html中
Dec 01 jQuery
jQuery 同时获取多个标签的指定内容并储存为数组
Nov 20 jQuery
jquery获取img的src值实例介绍
Jan 16 jQuery
jQuery事件blur()方法的使用实例讲解
Mar 30 jQuery
如何在vue 中引入使用jquery
Nov 10 jQuery
使用jquery实现轮播图效果
Jan 02 jQuery
JavaScript实现的滚动公告特效【基于jQuery】
Jul 10 #jQuery
JavaScript前端页面搜索功能案例【基于jQuery】
Jul 10 #jQuery
jquery多级树形下拉菜单的实例代码
Jul 09 #jQuery
jQuery删除/清空指定元素的所有子节点实例代码
Jul 04 #jQuery
JQuery+Bootstrap 自定义全屏Loading插件的示例demo
Jul 03 #jQuery
jQuery属性选择器用法实例分析
Jun 28 #jQuery
jQuery位置选择器用法实例分析
Jun 28 #jQuery
You might like
PHP+Tidy-完美的XHTML纠错+过滤
2007/04/10 PHP
Smarty foreach控制循环次数的实现详解
2013/07/03 PHP
ThinkPHP5&amp;5.1框架关联模型分页操作示例
2019/08/03 PHP
PHP For循环字母A-Z当超过26个字母时输出AA,AB,AC
2020/02/16 PHP
PHP7修改的函数
2021/03/09 PHP
HTML复选框和单选框 checkbox和radio事件介绍
2012/12/12 Javascript
js取两个数组的交集|差集|并集|补集|去重示例代码
2013/08/07 Javascript
js简单正则验证汉字英文及下划线的方法
2016/11/28 Javascript
详解javascript获取url信息的常见方法
2016/12/19 Javascript
JS表单提交验证、input(type=number) 去三角 刷新验证码
2017/06/21 Javascript
angularJs使用ng-repeat遍历后选中某一个的方法
2018/09/30 Javascript
jQuery实现为table表格动态添加或删除tr功能示例
2019/02/19 jQuery
微信小程序导航栏跟随滑动效果的实现代码
2019/05/14 Javascript
javascript设计模式 ? 模板方法模式原理与用法实例分析
2020/04/23 Javascript
JavaScript中EventBus实现对象之间通信
2020/10/18 Javascript
python从ftp下载数据保存实例
2013/11/20 Python
python判断给定的字符串是否是有效日期的方法
2015/05/13 Python
Python中defaultdict与lambda表达式用法实例小结
2018/04/09 Python
python向已存在的excel中新增表,不覆盖原数据的实例
2018/05/02 Python
flask入门之文件上传与邮件发送示例
2018/07/18 Python
对python内置map和six.moves.map的区别详解
2018/12/19 Python
Python图像处理之gif动态图的解析与合成操作详解
2018/12/30 Python
使用Bazel编译TensorBoard教程
2020/02/15 Python
python字符串判断密码强弱
2020/03/18 Python
Python通过Pillow实现图片对比
2020/04/29 Python
Pytho爬虫中Requests设置请求头Headers的方法
2020/09/22 Python
python3代码输出嵌套式对象实例详解
2020/12/03 Python
Html5页面获取微信公众号的openid的方法
2020/05/12 HTML / CSS
Hotels.com香港酒店网:你的自由行酒店订房专家
2018/01/22 全球购物
如果重写了对象的equals()方法,需要考虑什么
2014/11/02 面试题
客户代表自我评价范例
2013/09/24 职场文书
2014自主招生自荐信策略
2014/01/27 职场文书
副厂长岗位职责
2014/02/02 职场文书
工资证明范本
2015/06/12 职场文书
高中语文教材(文学文化常识大全一)
2019/08/13 职场文书
Mysql如何实现不存在则插入,存在则更新
2022/03/25 MySQL