jQuery實(shí)現(xiàn)彈窗居中效果類(lèi)似alert()
更新時(shí)間:2017年02月27日 16:15:12 作者:yangzailu1990
本文給大家分享基于jquery實(shí)現(xiàn)彈窗居中效果類(lèi)似于alert(),代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下
效果圖如下所示:

廢話(huà)不多說(shuō)了,直接給大家貼代碼了,具體代碼如下所示:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>彈出確認(rèn)框始終位于窗口的中間位置的測(cè)試</title>
<style type="text/css">
.mask { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: #000; opacity: 0.5; filter: alpha(opacity=50); display: none; z-index: 99; }
.mess { position: absolute; display: none; width: 250px; height: 100px; border: 1px solid #ccc; background: #ececec; text-align: center; z-index: 101; }
</style>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.btn').click(function() {
$('.mask').css({'display': 'block'});
center($('.mess'));
check($(this).parent(), $('.btn1'), $('.btn2'));
});
// 居中
function center(obj) {
var screenWidth = $(window).width();
screenHeight = $(window).height(); //當(dāng)前瀏覽器窗口的 寬高
var scrolltop = $(document).scrollTop();//獲取當(dāng)前窗口距離頁(yè)面頂部高度
var objLeft = (screenWidth - obj.width())/2 ;
var objTop = (screenHeight - obj.height())/2 + scrolltop;
obj.css({left: objLeft + 'px', top: objTop + 'px','display': 'block'});
//瀏覽器窗口大小改變時(shí)
$(window).resize(function() {
screenWidth = $(window).width();
screenHeight = $(window).height();
scrolltop = $(document).scrollTop();
objLeft = (screenWidth - obj.width())/2 ;
objTop = (screenHeight - obj.height())/2 + scrolltop;
obj.css({left: objLeft + 'px', top: objTop + 'px','display': 'block'});
});
//瀏覽器有滾動(dòng)條時(shí)的操作、
$(window).scroll(function() {
screenWidth = $(window).width();
screenHeight = $(widow).height();
scrolltop = $(document).scrollTop();
objLeft = (screenWidth - obj.width())/2 ;
objTop = (screenHeight - obj.height())/2 + scrolltop;
obj.css({left: objLeft + 'px', top: objTop + 'px','display': 'block'});
});
}
//確定取消的操作
function check(obj, obj1, obj2) {
obj1.click(function() {
obj.remove();
closed($('.mask'), $('.mess'));
});
obj2.click(function() {
closed($('.mask'), $('.mess'));
}) ;
}
// 隱藏 的操作
function closed(obj1, obj2) {
obj1.hide();
obj2.hide();
}
});
</script>
</head>
<body>
<input type="button" class="btn" value="btn"/>
<div>彈出確認(rèn)框始終位于窗口的中間位置的測(cè)試</div>
<div class="mask"></div>
<div class="mess">
<p>確定要?jiǎng)h除嗎?</p>
<p><input type="button" value="確定" class="btn1"/>
<input type="button" value="取消"class="btn2"/></p>
</div>
</body>
</html>
以上所述是小編給大家介紹的jQuery實(shí)現(xiàn)彈窗居中效果類(lèi)似alert(),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
您可能感興趣的文章:
- jQuery實(shí)現(xiàn)的兩種簡(jiǎn)單彈窗效果示例
- jquery實(shí)現(xiàn)彈窗(系統(tǒng)提示框)效果
- Jquery實(shí)現(xiàn)自定義彈窗示例
- jquery ui dialog實(shí)現(xiàn)彈窗特效的思路及代碼
- 小巧強(qiáng)大的jquery layer彈窗彈層插件
- 簡(jiǎn)單實(shí)現(xiàn)jQuery彈窗效果
- jquery實(shí)現(xiàn)彈窗功能(窗口居中顯示)
- jquery制作彈窗提示窗口代碼分享
- 運(yùn)用JQuery的toggle實(shí)現(xiàn)網(wǎng)頁(yè)加載完成自動(dòng)彈窗
- jquery實(shí)現(xiàn)簡(jiǎn)單的彈窗效果
相關(guān)文章
jquery實(shí)現(xiàn)select選中行、列合計(jì)示例
這篇文章主要介紹了jquery如何實(shí)現(xiàn)select選中行、列合計(jì)示例 ,需要的朋友可以參考下2014-04-04
JQuery Tips相關(guān)(1)----關(guān)于$.Ready()
學(xué)習(xí)jQuery的第一件事是:如果你想要一個(gè)事件運(yùn)行在你的頁(yè)面上,你必須在$(document).ready()里調(diào)用這個(gè)事件。所有包括在$(document).ready()里面的元素或事件都將會(huì)在DOM完成加載之后立即加載,并且在頁(yè)面內(nèi)容加載之前。2014-08-08
asp.net中oracle 存儲(chǔ)過(guò)程(圖文)
存儲(chǔ)過(guò)程是在大型數(shù)據(jù)庫(kù)系統(tǒng)中,一組為了完成特定功能的sql語(yǔ)句集,經(jīng)過(guò)編譯存儲(chǔ)在數(shù)據(jù)庫(kù)中,用戶(hù)通過(guò)指定存儲(chǔ)過(guò)程的名字并給出參數(shù)(如果該存儲(chǔ)過(guò)程帶有參數(shù))來(lái)執(zhí)行它,下面小編給大家介紹asp.net中oracle存儲(chǔ)過(guò)程,需要的朋友可以參考下2015-08-08

