JQuery彈出層示例可自定義
更新時(shí)間:2014年05月19日 17:18:37 作者:
JQuery實(shí)現(xiàn)的彈出層,js和css可根據(jù)自己的實(shí)際情況而定,下面是具體的實(shí)現(xiàn)代碼,大家不妨參考下
1、創(chuàng)建一個(gè)jsp頁(yè)面,內(nèi)容如下,js和css根據(jù)自己的實(shí)際情況而定
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="Share.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../js/common/jquery-1.11.0.js"></script>
<script type="text/javascript" src="popup.js"></script>
<script type="text/javascript" src="testPopup.js"></script>
</head>
<body>
<div id="right">
<div class="right_nav">
<h1>用戶管理</h1>
<a href="#" onclick="" class="but_tj">添加</a>
</div>
<div class="overlay" id="spm" style="display: none;"></div><!-- 將彈出層下面的頁(yè)面變成不可操作狀態(tài),成半透明狀態(tài) -->
<div class="Popup" style="display: none">,<!-- 隱藏div -->
<div class="Popup_top">
<h1>添加</h1>
<a href="#" class="Close"><img alt="關(guān)閉" src="close.png" /></a>
</div>
<div class="Popup_cen">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="BD_tab">
<tr>
<td style="width: 110px;" align="right">姓名:</td>
<td><input name="" id="name" type="text" class="input220"
onfocus="this.className='input220L';this.onmouseout=''"
onblur="this.className='input220';this.onmouseout=function(){this.className='input220'};"
onmousemove="this.className='input220Lg'"
onmouseout="this.className='input220'"> <font color="red">*</font></td>
</tr>
<tr>
<td align="right">昵稱:</td>
<td><input name="" id="nickname" type="text" class="input220"
onfocus="this.className='input220L';this.onmouseout=''"
onblur="this.className='input220';this.onmouseout=function(){this.className='input220'};"
onmousemove="this.className='input220Lg'"
onmouseout="this.className='input220'"> <font color="red">*</font></td>
</tr>
<tr>
<td style="width: 110px;" align="right">賬號(hào):</td>
<td><input name="" id="account" type="text" class="input220"
onfocus="this.className='input220L';this.onmouseout=''"
onblur="this.className='input220';this.onmouseout=function(){this.className='input220'};"
onmousemove="this.className='input220Lg'"
onmouseout="this.className='input220'"> <font color="red">*</font></td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
2、公用的帶有彈出層和關(guān)閉層的兩個(gè)方法
//popup layer
function isIE(num){
var num = num || "",
tester = document.createElement('div');
tester.innerHTML = '<!--[if IE ' + num + ']><i></i><![endif]-->';
return !!tester.getElementsByTagName('i')[0];
}
function popupLayer(objClass,targetClass){
$("."+objClass).click(function(){
$("#spm").show();
var target=$("."+targetClass);
var targetWidth=target.outerWidth();
var targetHeight=target.outerHeight();
if(isIE(6)){
$("#spm").hide();
//$("select").hide();
var top=$(document).scrollTop()+$(window).height()/2;
target.css({"top":top+"px"});
$(window).scroll(function(){
var top=$(document).scrollTop()+$(window).height()/2;
target.css({"top":top+"px"});
});
}
target.css({"margin-top":-parseInt(targetHeight/2)+"px","margin-left":-parseInt(targetWidth/2)+"px"});
target.show();
return false;
});
}
//隱藏div的操作
function closeLayer(objClass,targetClass)
{
$("."+objClass).click(function(){
$(this).parents("."+targetClass).hide();
$("#spm").hide();
});
}
3、1中調(diào)用3中js實(shí)現(xiàn)效果的js代碼
$(function(){
//第一個(gè)參數(shù)是按鈕的class屬性值,第二個(gè)是被隱藏的div屬性值
popupLayer("but_tj","Popup");
closeLayer("Close","Popup");
});
//我們通過(guò)點(diǎn)擊添加或修改按鈕后使當(dāng)前操作的div隱藏
//closeAdd("Popup");
function closeAdd(targetClass){
$("."+targetClass).hide();
$("#spm").hide();
}
4、css樣式
html {min-height: 100%;position: relative;overflow: hidden;}
body {background-color: #FFF;font: 12px 微軟雅黑, Arial, sans-serif;margin: 0;}
h1 {font-size: 12px;font-size: inherit;font-weight: normal;}
a {text-decoration: none;}
a:hover {text-decoration: none;}
.clear {overflow: hidden;clear: both;}
#right {margin-left: 190px;min-height: 100%;padding: 0;}
.right_top {height: 40px;background-color: #f5f5f5;color: #666666;border-bottom: 1px solid #e5e5e5;line-height: 40px;padding-left: 50px;position: relative;z-index: 1;}
.right_top a {color: #2b7dbc;}
.right_nav {margin: 0 30px;height: 37px;background-color: #438eb9;line-height: 37px;position: relative;margin-top: 15px;}
.right_nav h1 {font-size: 18px;color: #ffffff;padding-left: 20px;}
.but_tj {width: 68px;height: 27px;display: block;position: absolute;top: 7px;right: 30px;background: url(but_JG.png) no-repeat;text-align: center;line-height: 27px;font-size: 14px;color: #FFF;}
.but_tj:hover {background: url(but_JG1.png) no-repeat;}
.pind20 {padding-left: 20px;}
/*Popup*/
.Popup {width: 770px;height: 500px;position: absolute;left: 50%;top: 50%;margin-left: -400px;padding: 0 15px;margin-top: -250px;background-color: #FFF;border: 3px solid #006caa;z-index: 999;}
.Popup_top {height: 40px;line-height: 40px;border-bottom: 1px solid #cccccc;}
.Popup_top h1 {float: left;font-size: 14px;}
.Close {float: right;font-family: Arial, Helvetica, sans-serif;margin-right: 10px;margin-top: 10px;}
.Popup_cen {padding-top: 10px;width: 100%;height: 440px;overflow: auto;}
.Popup_audit {padding-top: 10px;width: 100%;height: 440px;}
.overlay {position: fixed;z-index: 990;width: 100%;height: 100%;top: 0;left: 0;filter: alpha(opacity = 60);opacity: 0.6;overflow: hidden;background-color: #000;}
/*BD_tab*/
.BD_tab {width: 500px;margin: 0 auto;}
.BD_tab td {padding-top: 12px;}
.input220,.input220L,.input220Lg {width: 220px;height: 28px;border: 1px solid #d3d3d3;padding-left: 5px;line-height: 28px;font-family: "微軟雅黑";color: #000;}
.input220L {border: 1px solid #377bcb;background-color: #d5e8ff;}
.input220Lg {border: 1px solid #7fb1eb;background-color: #d8e6f7;}
.input220 {border: 1px solid #d3d3d3;}
效果如下圖
復(fù)制代碼 代碼如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="Share.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../js/common/jquery-1.11.0.js"></script>
<script type="text/javascript" src="popup.js"></script>
<script type="text/javascript" src="testPopup.js"></script>
</head>
<body>
<div id="right">
<div class="right_nav">
<h1>用戶管理</h1>
<a href="#" onclick="" class="but_tj">添加</a>
</div>
<div class="overlay" id="spm" style="display: none;"></div><!-- 將彈出層下面的頁(yè)面變成不可操作狀態(tài),成半透明狀態(tài) -->
<div class="Popup" style="display: none">,<!-- 隱藏div -->
<div class="Popup_top">
<h1>添加</h1>
<a href="#" class="Close"><img alt="關(guān)閉" src="close.png" /></a>
</div>
<div class="Popup_cen">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="BD_tab">
<tr>
<td style="width: 110px;" align="right">姓名:</td>
<td><input name="" id="name" type="text" class="input220"
onfocus="this.className='input220L';this.onmouseout=''"
onblur="this.className='input220';this.onmouseout=function(){this.className='input220'};"
onmousemove="this.className='input220Lg'"
onmouseout="this.className='input220'"> <font color="red">*</font></td>
</tr>
<tr>
<td align="right">昵稱:</td>
<td><input name="" id="nickname" type="text" class="input220"
onfocus="this.className='input220L';this.onmouseout=''"
onblur="this.className='input220';this.onmouseout=function(){this.className='input220'};"
onmousemove="this.className='input220Lg'"
onmouseout="this.className='input220'"> <font color="red">*</font></td>
</tr>
<tr>
<td style="width: 110px;" align="right">賬號(hào):</td>
<td><input name="" id="account" type="text" class="input220"
onfocus="this.className='input220L';this.onmouseout=''"
onblur="this.className='input220';this.onmouseout=function(){this.className='input220'};"
onmousemove="this.className='input220Lg'"
onmouseout="this.className='input220'"> <font color="red">*</font></td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
2、公用的帶有彈出層和關(guān)閉層的兩個(gè)方法
復(fù)制代碼 代碼如下:
//popup layer
function isIE(num){
var num = num || "",
tester = document.createElement('div');
tester.innerHTML = '<!--[if IE ' + num + ']><i></i><![endif]-->';
return !!tester.getElementsByTagName('i')[0];
}
function popupLayer(objClass,targetClass){
$("."+objClass).click(function(){
$("#spm").show();
var target=$("."+targetClass);
var targetWidth=target.outerWidth();
var targetHeight=target.outerHeight();
if(isIE(6)){
$("#spm").hide();
//$("select").hide();
var top=$(document).scrollTop()+$(window).height()/2;
target.css({"top":top+"px"});
$(window).scroll(function(){
var top=$(document).scrollTop()+$(window).height()/2;
target.css({"top":top+"px"});
});
}
target.css({"margin-top":-parseInt(targetHeight/2)+"px","margin-left":-parseInt(targetWidth/2)+"px"});
target.show();
return false;
});
}
//隱藏div的操作
function closeLayer(objClass,targetClass)
{
$("."+objClass).click(function(){
$(this).parents("."+targetClass).hide();
$("#spm").hide();
});
}
3、1中調(diào)用3中js實(shí)現(xiàn)效果的js代碼
復(fù)制代碼 代碼如下:
$(function(){
//第一個(gè)參數(shù)是按鈕的class屬性值,第二個(gè)是被隱藏的div屬性值
popupLayer("but_tj","Popup");
closeLayer("Close","Popup");
});
//我們通過(guò)點(diǎn)擊添加或修改按鈕后使當(dāng)前操作的div隱藏
//closeAdd("Popup");
function closeAdd(targetClass){
$("."+targetClass).hide();
$("#spm").hide();
}
4、css樣式
復(fù)制代碼 代碼如下:
html {min-height: 100%;position: relative;overflow: hidden;}
body {background-color: #FFF;font: 12px 微軟雅黑, Arial, sans-serif;margin: 0;}
h1 {font-size: 12px;font-size: inherit;font-weight: normal;}
a {text-decoration: none;}
a:hover {text-decoration: none;}
.clear {overflow: hidden;clear: both;}
#right {margin-left: 190px;min-height: 100%;padding: 0;}
.right_top {height: 40px;background-color: #f5f5f5;color: #666666;border-bottom: 1px solid #e5e5e5;line-height: 40px;padding-left: 50px;position: relative;z-index: 1;}
.right_top a {color: #2b7dbc;}
.right_nav {margin: 0 30px;height: 37px;background-color: #438eb9;line-height: 37px;position: relative;margin-top: 15px;}
.right_nav h1 {font-size: 18px;color: #ffffff;padding-left: 20px;}
.but_tj {width: 68px;height: 27px;display: block;position: absolute;top: 7px;right: 30px;background: url(but_JG.png) no-repeat;text-align: center;line-height: 27px;font-size: 14px;color: #FFF;}
.but_tj:hover {background: url(but_JG1.png) no-repeat;}
.pind20 {padding-left: 20px;}
/*Popup*/
.Popup {width: 770px;height: 500px;position: absolute;left: 50%;top: 50%;margin-left: -400px;padding: 0 15px;margin-top: -250px;background-color: #FFF;border: 3px solid #006caa;z-index: 999;}
.Popup_top {height: 40px;line-height: 40px;border-bottom: 1px solid #cccccc;}
.Popup_top h1 {float: left;font-size: 14px;}
.Close {float: right;font-family: Arial, Helvetica, sans-serif;margin-right: 10px;margin-top: 10px;}
.Popup_cen {padding-top: 10px;width: 100%;height: 440px;overflow: auto;}
.Popup_audit {padding-top: 10px;width: 100%;height: 440px;}
.overlay {position: fixed;z-index: 990;width: 100%;height: 100%;top: 0;left: 0;filter: alpha(opacity = 60);opacity: 0.6;overflow: hidden;background-color: #000;}
/*BD_tab*/
.BD_tab {width: 500px;margin: 0 auto;}
.BD_tab td {padding-top: 12px;}
.input220,.input220L,.input220Lg {width: 220px;height: 28px;border: 1px solid #d3d3d3;padding-left: 5px;line-height: 28px;font-family: "微軟雅黑";color: #000;}
.input220L {border: 1px solid #377bcb;background-color: #d5e8ff;}
.input220Lg {border: 1px solid #7fb1eb;background-color: #d8e6f7;}
.input220 {border: 1px solid #d3d3d3;}
效果如下圖
您可能感興趣的文章:
- jQuery+CSS3+Html5實(shí)現(xiàn)彈出層效果實(shí)例代碼(附源碼下載)
- Jquery+CSS3實(shí)現(xiàn)一款簡(jiǎn)潔大氣帶滑動(dòng)效果的彈出層
- jQuery Dialog 彈出層對(duì)話框插件
- jQuery彈出層始終垂直居中相對(duì)于屏幕或當(dāng)前窗口
- jquery實(shí)現(xiàn)居中彈出層代碼
- jQuery+html5實(shí)現(xiàn)div彈出層并遮罩背景
- jQuery插件zoom實(shí)現(xiàn)圖片全屏放大彈出層特效
- JQUERY THICKBOX彈出層插件
- jQuery Mobile彈出窗、彈出層知識(shí)匯總
- jQuery點(diǎn)縮略圖彈出層顯示大圖片
- jQuery Layer彈出層傳值到父頁(yè)面的實(shí)現(xiàn)代碼
- jquery+css3實(shí)現(xiàn)的經(jīng)典彈出層效果示例
相關(guān)文章
基于jQuery替換table中的內(nèi)容并顯示進(jìn)度條的代碼
這個(gè)例子使我更加明白呈現(xiàn)數(shù)據(jù)是前端工作滴一部分,如何使table中的數(shù)值變?yōu)榍逦貤l狀圖呢?聽我細(xì)細(xì)道來(lái)2011-08-08
jQuery實(shí)現(xiàn)頁(yè)碼跳轉(zhuǎn)式動(dòng)態(tài)數(shù)據(jù)分頁(yè)
本片文章教給大家用jQuery實(shí)現(xiàn)頁(yè)碼跳轉(zhuǎn)式動(dòng)態(tài)數(shù)據(jù)分頁(yè),效果非常好而且沒有頁(yè)面刷新,需要的朋友學(xué)習(xí)下吧。2017-12-12
jQuery實(shí)現(xiàn)的Tab滑動(dòng)選項(xiàng)卡及圖片切換(多種效果)小結(jié)
這篇文章主要介紹了jQuery實(shí)現(xiàn)的Tab滑動(dòng)選項(xiàng)卡及圖片切換效果小結(jié),實(shí)例總結(jié)了幾種常見的tab切換效果,包括鼠標(biāo)點(diǎn)擊切換、滑過(guò)切換、定時(shí)自動(dòng)切換等,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-09-09
jQuery Mobile操作HTML5的常用函數(shù)總結(jié)
jQuery Mobile是針對(duì)移動(dòng)端開發(fā)的JavaScript框架,正如其名基于jQuery庫(kù),jQuery Mobile主要被用來(lái)操作HTML5設(shè)計(jì)頁(yè)面UI,下面就來(lái)看一下jQuery Mobile操作HTML5的常用函數(shù)總結(jié):2016-05-05
實(shí)例講解jquery中mouseleave和mouseout的區(qū)別
這篇文章主要以實(shí)例詳細(xì)講解了jquery中mouseleave和mouseout的區(qū)別,模仿下拉框效果,感興趣的小伙伴們可以參考一下2016-02-02
jquery validation插件表單驗(yàn)證的一個(gè)例子
jquery.validate.js validation表單的驗(yàn)證插件2010-03-03
jquery+ajax每秒向后臺(tái)發(fā)送請(qǐng)求數(shù)據(jù)然后返回頁(yè)面的代碼
jquery+ajax每秒向后臺(tái)發(fā)送請(qǐng)求數(shù)據(jù)然后返回頁(yè)面(包括jquery頁(yè)面加載完畢才執(zhí)行方法)2011-01-01

