JavaScript实现的弹出遮罩层特效经典示例【基于
网络编程 2021-07-04 15:51www.168986.cn编程入门
这篇文章主要介绍了JavaScript实现的弹出遮罩层特效,结合实例形式分析了基于jQuery实现的页面元素与属性动态操作相关使用技巧,需要的朋友可以参考下
本文实例讲述了JavaScript实现的弹出遮罩层特效。分享给大家供大家参考,具体如下
这篇给大家分享一个简单的遮罩层特效,先上效果图。
代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>查看,修改,删除</title> <script src="http://libs.baidu./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; :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', '':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代码运行工具测试上述代码运行效果。
更多关于jQuery相关内容可查看本站专题《》、《》、《》、《》及《》
希望本文所述对大家jQuery程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程