jquery實(shí)現(xiàn)彈窗功能(窗口居中顯示)
更新時間:2017年02月27日 15:43:55 作者:yangzailu1990
本文主要介紹了jquery實(shí)現(xiàn)彈窗功能且彈出確認(rèn)框始終位于窗口中間位置的實(shí)例,具有很好的參考價值,下面跟著小編一起來看下吧
效果圖:

代碼如下:
<!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'});
//瀏覽器窗口大小改變時
$(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'});
});
//瀏覽器有滾動條時的操作、
$(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>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
您可能感興趣的文章:
- 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)彈窗居中效果類似alert()
- jquery制作彈窗提示窗口代碼分享
- 運(yùn)用JQuery的toggle實(shí)現(xiàn)網(wǎng)頁加載完成自動彈窗
- jquery實(shí)現(xiàn)簡單的彈窗效果
相關(guān)文章
jQuery實(shí)現(xiàn)簡單的手風(fēng)琴效果
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)簡單的手風(fēng)琴效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06
基于jQuery Circlr插件實(shí)現(xiàn)產(chǎn)品圖片360度旋轉(zhuǎn)
Circlr是一款可以對產(chǎn)品圖片進(jìn)行360度全方位旋轉(zhuǎn)展示的jQuery插件,本文給大家分享一款基于jQuery Circlr插件實(shí)現(xiàn)產(chǎn)品圖片360度旋轉(zhuǎn),大家一起來看看吧2015-09-09
Jquery Easyui搜索框組件SearchBox使用詳解(19)
這篇文章主要為大家詳細(xì)介紹了Jquery Easyui搜索框組件SearchBox的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12
jQuery綁定事件-多種實(shí)現(xiàn)方式總結(jié)
下面小編就為大家?guī)硪黄猨Query綁定事件-多種實(shí)現(xiàn)方式總結(jié)。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考2016-05-05
jquery獲取div寬度的實(shí)現(xiàn)思路與代碼
DIV的width寬度如何獲取呢?接下來介紹使用jquery獲取DIV的width寬度,感興趣的朋友可以了解下的2013-01-01
jQuery實(shí)現(xiàn)智能判斷固定導(dǎo)航條或側(cè)邊欄的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)智能判斷固定導(dǎo)航條或側(cè)邊欄的方法,涉及jQuery針對頁面元素屬性的判斷與動態(tài)操作相關(guān)技巧,需要的朋友可以參考下2016-09-09
基于JQuery實(shí)現(xiàn)滾動到頁面底端時自動加載更多信息
這篇文章主要介紹了基于JQuery實(shí)現(xiàn)滾動到頁面底端時自動加載更多信息,類似微博,新浪新聞的評論等,都采用了這方法,需要的朋友可以參考下2014-01-01

