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源码解读之extend()与工具方法、实例方法详解
Mar 30 jQuery
jQuery实现div跟随鼠标移动
Aug 20 jQuery
jQuery实现动态删除LI的方法
May 30 jQuery
jquery图片放大镜效果
Jun 23 jQuery
jQuery动态添加.active 实现导航效果代码思路详解
Aug 29 jQuery
jQuery简单实现的HTML页面文本框模糊匹配查询功能完整示例
May 09 jQuery
jQuery选择器选中最后一个元素,倒数第二个元素操作示例
Dec 10 jQuery
jQuery使用bind动态绑定事件无效的处理方法
Dec 11 jQuery
jQuery实现的分页插件完整示例
May 26 jQuery
jQuery实现回到顶部效果
Oct 19 jQuery
JQuery绑定事件四种实现方法解析
Dec 02 jQuery
jQuery实现简单轮播图效果
Dec 27 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的类树(支持无限分类)
2006/10/09 PHP
我的论坛源代码(六)
2006/10/09 PHP
php+mysql实现无限级分类 | 树型显示分类关系
2006/11/19 PHP
PHP中的CMS的涵义
2007/03/11 PHP
PHP5权威编程阅读学习笔记 附电子书下载
2012/07/05 PHP
php数组编码转换示例详解
2014/03/11 PHP
thinkPHP5框架设置404、403等http状态页面的方法
2018/06/05 PHP
客户端静态页面玩分页
2006/06/26 Javascript
JavaScript的Function详细
2006/11/14 Javascript
js change,propertychange,input事件小议
2011/12/20 Javascript
jquery快捷动态绑定键盘事件的操作函数代码
2013/10/17 Javascript
Chrome扩展页面动态绑定JS事件提示错误
2014/02/11 Javascript
IE6/IE7中JavaScript json提示缺少标识符、字符串或数字问题处理
2014/12/16 Javascript
jQuery的text()方法用法分析
2014/12/20 Javascript
js实现上传图片预览的方法
2015/02/09 Javascript
JavaScript判断用户是否对表单进行了修改的方法
2015/03/18 Javascript
EasyUi中的Combogrid 实现分页和动态搜索远程数据
2016/04/01 Javascript
AngularJs 弹出模态框(model)
2016/04/07 Javascript
浅析jQuery 遍历函数,javascript中的each遍历
2016/05/25 Javascript
vue实现添加标签demo示例代码
2017/01/21 Javascript
Java中int与integer的区别(基本数据类型与引用数据类型)
2017/02/19 Javascript
H5手机端多文件上传预览插件
2017/04/21 Javascript
javascript少儿编程关于返回值的函数内容
2018/05/27 Javascript
vue项目创建并引入饿了么elementUI组件的步骤
2019/04/11 Javascript
浅谈实现在线预览PDF的几种解决办法
2020/08/10 Javascript
Vue 数据响应式相关总结
2021/01/28 Vue.js
Python pass 语句使用示例
2014/03/11 Python
Python实现将SQLite中的数据直接输出为CVS的方法示例
2017/07/13 Python
matplotlib.pyplot画图 图片的二进制流的获取方法
2018/05/24 Python
使用 pytorch 创建神经网络拟合sin函数的实现
2020/02/24 Python
Python进程间通信multiprocess代码实例
2020/03/18 Python
python安装第三方库如xlrd的方法
2020/10/31 Python
上海期货面试题
2014/01/31 面试题
2015中秋节晚会主持词
2015/07/01 职场文书
大学生干部培训心得体会
2016/01/06 职场文书
MySQL约束超详解
2021/09/04 MySQL