jQuery實現(xiàn)單擊按鈕遮罩彈出對話框效果(1)
本文實例為大家分享了jQuery實現(xiàn)單擊按鈕遮罩彈出對話框的具體代碼,供大家參考,具體內(nèi)容如下
看到網(wǎng)上一位大神的代碼后,大概進行了注釋,調(diào)試了一下頁面以后感覺不錯,留作以后使用。
主要用到了:/jquery-1.10.2.min.js
代碼如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>遮罩彈出窗口</title>
<script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>
<style type="text/css">
/* CSS Document */
@CHARSET "UTF-8";
*{
margin: 0px;
padding: 0px;
}
.divShow{
/*設(shè)置字體高度
div的高度
背景色
div寬度
左內(nèi)距為10px
*/
line-height: 50px;
height: 60px;
background-color: #dddddd;
width: 300px;
padding-left: 15px;
}
.dialog{
/*
設(shè)置寬度
設(shè)置邊框?qū)挾?顏色+引
display:none表示影藏
z-index://保證該層在最上面顯示
*/
width: 360px;
border: 10px #fff solid;
position: absolute;
display: none;
z-index: 101;
}
.dialog .title{
/*
設(shè)置背景色
設(shè)置內(nèi)邊距
設(shè)置字體顏色
設(shè)置字體加粗
*/
background:#fbaf15;
padding: 10px;
color: #fff;
font-weight: bold;
}
.dialog .title img{
/*
設(shè)置元素向右浮動
*/
float:right;
}
.dialog .content{
/*
設(shè)置背景色
設(shè)置內(nèi)邊距
設(shè)置高度
*/
background: #fff;
padding: 25px;
height: 60px;
}
.dialog .content img{
float: left;
}
.dialog .content span{
float: left;
padding: 10px;
}
.dialog .bottom{
/*
設(shè)置文本向右對齊
設(shè)置內(nèi)邊局 上右下左
*/
text-align: right;
padding: 10 10 10 0;
background: #eee;
}
.mask{
/*
里面有個display:no;
開始的時候看不到這個div的效果它主要作用是封閉整個頁面
*/
width: 100%;
height: 100%;
background: #000;
position: absolute;
top: 0px;
left: 0px;
display: none;
z-index: 100;
}
.btn{
border: #666 1px solid;
width: 65px;
}
</style>
<script type="text/javascript">
// JavaScript Document$(function(){
//綁定刪除按鈕的觸發(fā)事件
$(document).ready(function(){
//按下按鈕觸發(fā)操作
$("#button1").click(function(){
//設(shè)置 div 元素的不透明級別:透明度取值(取值范圍[0.0,1.0])
$(".mask").css("opacity","0.3").show();
//制作對話框
showDialog();
//展現(xiàn)css的特效
$(".dialog").show();
});
//當頁面窗口大小改變時觸發(fā)的事件
$(window).resize(function(){
if(!$(".dialog").is(":visible")){
return;
}
showDialog();
});
//注冊關(guān)閉圖片單擊事件
$(".title img").click(function(){
//隱藏效果
$(".dialog").hide();
$(".mask").hide();
});
//取消按鈕事件
$("#noOk").click(function(){
$(".dialog").hide();
$(".mask").hide();
});
//確定按鈕事假
$("#ok").click(function(){
$(".dialog").hide();
$(".mask").hide();
if($("input:checked").length !=0){
//注意過濾器選擇器中間不能存在空格$("input :checked")這樣是錯誤的
$(".divShow").remove();//刪除某條數(shù)據(jù)
}
});
});
/*
* 根據(jù)當前頁面于滾動條的位置,設(shè)置提示對話框的TOP和left
*/
function showDialog(){
var objw=$(window);//獲取當前窗口
var objc=$(".dialog");//獲取當前對話框
var brsw=objw.width(); //獲取頁面寬度
var brsh=objw.height(); //獲取頁面高度
var sclL=objw.scrollLeft(); //獲取頁面左滑動條信息
var sclT=objw.scrollTop();
var curw=objc.width(); //獲取對話框?qū)挾?
var curh=objc.height(); //獲取對話框高度
var left=sclL+(brsw -curw)/2; //計算對話框居中時的左邊距
var top=sclT+(brsh-curh)/2; //計算對話框居中時的上邊距
objc.css({"left":left,"top":top}); //設(shè)置對話框居中
}
</script>
</head>
<body>
<div class="divShow">
<input type="checkbox" id="chexkBox1"> <a href="#">這是一條可以刪除的記錄</a>
<input id="button1" type="button" value="刪除" class="btn">
</div>
<div class="mask"></div>
<div class="dialog">
<div class="title">
<img alt="點擊可以關(guān)閉" src="" width="20px" height="20px;">
刪除時提示
</div>
<div class="content">
<img alt="" src="" width="60px" height="60px">
<span>你真的要刪除這條記錄嗎?</span>
</div>
<div class="bottom">
<input type="button" id="ok" value="確定" class="btn">
<input type="button" id="noOk" value="取消" class="btn">
</div>
</div>
</body>
</html>
展示一張在谷歌上的效果:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用jQuery快速解決input中placeholder值在ie中無法支持的問題
本篇文章主要介紹了使用jQuery快速解決input中placeholder值在ie中無法支持的問題。需要的朋友可以過來參考下,希望對大家有所幫助2014-01-01
淺析jQuery的鏈式調(diào)用之each函數(shù)
如果對于jquery的$()包裝器函數(shù)還不是很清楚,請先參閱我的上一篇日志:淺析jQuery的鏈式調(diào)用2010-12-12
jQuery EasyUI Pagination實現(xiàn)分頁的常用方法
這篇文章主要為大家詳細介紹了jQuery EasyUI Pagination實現(xiàn)分頁的常用方法,感興趣的朋友可以參考一下2016-05-05
jQuery實現(xiàn)對象轉(zhuǎn)為url參數(shù)的方法
這篇文章主要介紹了jQuery實現(xiàn)對象轉(zhuǎn)為url參數(shù)的方法,涉及jQuery針對字符串的遍歷與轉(zhuǎn)換操作相關(guān)技巧,需要的朋友可以參考下2017-01-01
jQuery 利用ztree實現(xiàn)樹形表格的實例代碼
最近公司要做一個樹形表格,由于之前對ztree實現(xiàn)基本的樹形結(jié)構(gòu),所以想到用ztree來做,下面小編給大家分享實現(xiàn)代碼,感興趣的朋友一起看看吧2017-09-09
jquery使用slideDown實現(xiàn)模塊緩慢拉出效果的方法
這篇文章主要介紹了jquery使用slideDown實現(xiàn)模塊緩慢拉出效果的方法,涉及slideDown方法操作模塊展示效果的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03

