jQuery實(shí)現(xiàn)彈窗居中效果類似alert()
效果圖如下所示:

廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>彈出確認(rèn)框始終位于窗口的中間位置的測試</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)前窗口距離頁面頂部高度
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'});
});
//瀏覽器有滾動條時(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)框始終位于窗口的中間位置的測試</div>
<div class="mask"></div>
<div class="mess">
<p>確定要刪除嗎?</p>
<p><input type="button" value="確定" class="btn1"/>
<input type="button" value="取消"class="btn2"/></p>
</div>
</body>
</html>
以上所述是小編給大家介紹的jQuery實(shí)現(xiàn)彈窗居中效果類似alert(),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- jQuery實(shí)現(xiàn)的兩種簡單彈窗效果示例
- jquery實(shí)現(xiàn)彈窗(系統(tǒng)提示框)效果
- Jquery實(shí)現(xiàn)自定義彈窗示例
- jquery ui dialog實(shí)現(xiàn)彈窗特效的思路及代碼
- 小巧強(qiáng)大的jquery layer彈窗彈層插件
- 簡單實(shí)現(xiàn)jQuery彈窗效果
- jquery實(shí)現(xiàn)彈窗功能(窗口居中顯示)
- jquery制作彈窗提示窗口代碼分享
- 運(yùn)用JQuery的toggle實(shí)現(xiàn)網(wǎng)頁加載完成自動彈窗
- jquery實(shí)現(xiàn)簡單的彈窗效果
相關(guān)文章
基于jquery的劃詞搜索實(shí)現(xiàn)(備忘)
最近,需要做個劃詞搜索功能。在網(wǎng)上找了好些,最后,參照進(jìn)行修改,實(shí)現(xiàn)了想要的功能。這里,做個記錄,以備日后所用。2010-09-09
jquery實(shí)現(xiàn)兼容瀏覽器的圖片上傳本地預(yù)覽功能
圖片上傳本地預(yù)覽功能代碼在網(wǎng)上可以搜索很多,但同時(shí)可以兼容瀏覽器的話就多了,本文有個不錯的示例,感興趣的朋友可以參考下2013-10-10
jQuery源碼解讀之extend()與工具方法、實(shí)例方法詳解
這篇文章主要介紹了jQuery源碼解讀之extend()與工具方法、實(shí)例方法,分析了jQuery中extend()源碼、功能與相關(guān)使用技巧,需要的朋友可以參考下2017-03-03
JQuery 風(fēng)格的HTML文本轉(zhuǎn)義
astinus開發(fā)過程中,我自己就在不斷的使用。有次貼了一些JS代碼進(jìn)去,于是頁面顯示錯誤。顯然,把源代碼直接放進(jìn)html文本了——好吧,從05年轉(zhuǎn)去做網(wǎng)游以后,一直沒有正經(jīng)的做過web了。2009-07-07
jquery簡單瀑布流實(shí)現(xiàn)原理及ie8下測試代碼
可以將分頁獲取的內(nèi)容依次填入四個div中,瀑布流的分頁可以以多頁(比如5頁)為單位二次分頁,這樣可以減少后臺算法的復(fù)雜度;測試環(huán)境:ie8 ff13.0.1 chrome22有興趣的朋友可以了解下2013-01-01
jquery表單驗(yàn)證實(shí)例仿Toast提示效果
這篇文章主要介紹了jquery驗(yàn)證表單仿Toast提示效果,實(shí)現(xiàn)代碼簡單易懂,非常不錯,需要的朋友可以參考下2017-03-03
jQuery獲取選中內(nèi)容及設(shè)置元素屬性的方法
這篇文章主要介紹了jQuery獲取選中內(nèi)容及設(shè)置元素屬性的方法,需要的朋友可以參考下2014-07-07

