JavaScript實(shí)現(xiàn)的彈出遮罩層特效經(jīng)典示例【基于jQuery】
本文實(shí)例講述了JavaScript實(shí)現(xiàn)的彈出遮罩層特效。分享給大家供大家參考,具體如下:
這篇給大家分享一個簡單的遮罩層特效,先上效果圖。

代碼:
<!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>項(xiàng)目經(jīng)理</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" >關(guān)閉</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 = [];//保存數(shù)據(jù)的數(shù)組
//將一行的數(shù)據(jù)添加到數(shù)據(jù)中
$(this).parent().siblings().each(function(){
data.push($(this).text())
});
//將內(nèi)容顯示到彈出層中
$('div.proDiv').children().each(function(i){
$(this).children('span').text(data[i]);
});
$('div.proDiv').show();//顯示彈出層
//關(guān)閉操作
$('a.close').click(function(){
$(this).parent().hide();
$('div.mask').remove();
});
});
//刪除操作
$('a.del').click(function(){
$(this).parents('tr').remove();
});
</script>
</html>
頁面中有一個表格,一個隱藏的彈出層,當(dāng)點(diǎn)擊查看按鈕,首先創(chuàng)建一個遮罩層,然后獲取這一行中的數(shù)據(jù),并把數(shù)據(jù)顯示到彈出層中,最后把彈出層隱藏,點(diǎn)擊關(guān)閉按鈕關(guān)閉彈出層并關(guān)閉遮罩層。點(diǎn)擊刪除按鈕把這個tr刪除即可。
感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun測試上述代碼運(yùn)行效果。
更多關(guān)于jQuery相關(guān)內(nèi)容可查看本站專題:《jQuery頁面元素操作技巧匯總》、《jQuery常見事件用法與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
- JS遮罩層效果 兼容ie firefox jQuery遮罩層
- JQuery 遮罩層實(shí)現(xiàn)(mask)實(shí)現(xiàn)代碼
- jQuery操作dom實(shí)現(xiàn)彈出頁面遮罩層(web端和移動端阻止遮罩層的滑動)
- jQuery阻止移動端遮罩層后頁面滾動
- jQuery實(shí)現(xiàn)簡單網(wǎng)頁遮罩層/彈出層效果兼容IE6、IE7
- Jquery實(shí)現(xiàn)遮罩層的簡單實(shí)例(就是彈出DIV周圍都灰色不能操作)
- jQuery+AJAX實(shí)現(xiàn)遮罩層登錄驗(yàn)證界面(附源碼)
- jQuery點(diǎn)擊按鈕彈出遮罩層且內(nèi)容居中特效
- Jquery實(shí)現(xiàn)遮罩層的方法
- jQuery實(shí)現(xiàn)彈出帶遮罩層的居中浮動窗口效果
- jQuery實(shí)現(xiàn)打開網(wǎng)頁自動彈出遮罩層或點(diǎn)擊彈出遮罩層功能示例
相關(guān)文章
jQuery動態(tài)操作表單示例【基于table表格】
這篇文章主要介紹了jQuery動態(tài)操作表單,結(jié)合實(shí)例形式分析了jQuery針對table表格的數(shù)據(jù)添加、刪除、元素修改、提交等相關(guān)操作技巧,需要的朋友可以參考下2018-12-12
jQuery Validation實(shí)例代碼 讓驗(yàn)證變得如此容易
眾所周知,Jquery以其簡潔性讓無數(shù)人為之瘋狂?,F(xiàn)在我要像大家介紹一個jQuery Validation,一看到Validation大家肯定第一直觀感覺就是這肯定是一個驗(yàn)證框架,沒有錯,本文就是基于jQuery Validation展開討論。2010-10-10
jquery獲取url參數(shù)及url加參數(shù)的方法
本文給大家介紹jquery獲取url參數(shù)及url參數(shù)的方法,在url中加參數(shù)的方法本文通過多種方式給大家介紹jquery獲取url參數(shù),感興趣的朋友一起學(xué)習(xí)學(xué)習(xí)吧2015-10-10
jquery封裝插件時匿名函數(shù)形參和實(shí)參的寫法解釋
本文主要介紹了jquery封裝插件時匿名函數(shù)形參和實(shí)參的寫法解釋。具有很好的參考價值,下面跟著小編一起來看下吧2017-02-02
jQuery實(shí)現(xiàn)導(dǎo)航樣式布局操作示例【可自定義樣式布局】
這篇文章主要介紹了jQuery實(shí)現(xiàn)導(dǎo)航樣式布局操作,可實(shí)現(xiàn)基于jQuery的用戶自定義樣式布局與屬性動態(tài)操作相關(guān)技巧,需要的朋友可以參考下2018-07-07
JavaScript的jQuery庫中ready方法的學(xué)習(xí)教程
這篇文章主要介紹了JavaScript的jQuery庫中ready方法的學(xué)習(xí)教程,包括ready的相關(guān)簡短寫法,rally cool,需要的朋友可以參考下2015-08-08
jQuery實(shí)現(xiàn)可編輯的表格實(shí)例講解(2)
這篇文章主要內(nèi)容是JQuery實(shí)現(xiàn)可編輯的表格實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-09-09

