jQuery實(shí)現(xiàn)單擊按鈕遮罩彈出對(duì)話框效果(1)
本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)單擊按鈕遮罩彈出對(duì)話框的具體代碼,供大家參考,具體內(nèi)容如下
看到網(wǎng)上一位大神的代碼后,大概進(jìn)行了注釋,調(diào)試了一下頁(yè)面以后感覺(jué)不錯(cuò),留作以后使用。
主要用到了:/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è)置元素向右浮動(dòng)
*/
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è)置文本向右對(duì)齊
設(shè)置內(nèi)邊局 上右下左
*/
text-align: right;
padding: 10 10 10 0;
background: #eee;
}
.mask{
/*
里面有個(gè)display:no;
開(kāi)始的時(shí)候看不到這個(gè)div的效果它主要作用是封閉整個(gè)頁(yè)面
*/
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 元素的不透明級(jí)別:透明度取值(取值范圍[0.0,1.0])
$(".mask").css("opacity","0.3").show();
//制作對(duì)話框
showDialog();
//展現(xiàn)css的特效
$(".dialog").show();
});
//當(dāng)頁(yè)面窗口大小改變時(shí)觸發(fā)的事件
$(window).resize(function(){
if(!$(".dialog").is(":visible")){
return;
}
showDialog();
});
//注冊(cè)關(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){
//注意過(guò)濾器選擇器中間不能存在空格$("input :checked")這樣是錯(cuò)誤的
$(".divShow").remove();//刪除某條數(shù)據(jù)
}
});
});
/*
* 根據(jù)當(dāng)前頁(yè)面于滾動(dòng)條的位置,設(shè)置提示對(duì)話框的TOP和left
*/
function showDialog(){
var objw=$(window);//獲取當(dāng)前窗口
var objc=$(".dialog");//獲取當(dāng)前對(duì)話框
var brsw=objw.width(); //獲取頁(yè)面寬度
var brsh=objw.height(); //獲取頁(yè)面高度
var sclL=objw.scrollLeft(); //獲取頁(yè)面左滑動(dòng)條信息
var sclT=objw.scrollTop();
var curw=objc.width(); //獲取對(duì)話框?qū)挾?
var curh=objc.height(); //獲取對(duì)話框高度
var left=sclL+(brsw -curw)/2; //計(jì)算對(duì)話框居中時(shí)的左邊距
var top=sclT+(brsh-curh)/2; //計(jì)算對(duì)話框居中時(shí)的上邊距
objc.css({"left":left,"top":top}); //設(shè)置對(duì)話框居中
}
</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="點(diǎn)擊可以關(guān)閉" src="" width="20px" height="20px;">
刪除時(shí)提示
</div>
<div class="content">
<img alt="" src="" width="60px" height="60px">
<span>你真的要?jiǎng)h除這條記錄嗎?</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>
展示一張?jiān)诠雀枭系男Ч?/p>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jQuery實(shí)現(xiàn)首頁(yè)懸浮框
- 使用jQuery UI的tooltip函數(shù)修飾title屬性的氣泡懸浮框
- jQuery實(shí)現(xiàn)單擊按鈕遮罩彈出對(duì)話框效果(2)
- jQuery點(diǎn)擊按鈕彈出遮罩層且內(nèi)容居中特效
- jQuery實(shí)現(xiàn)點(diǎn)擊按鈕彈出可關(guān)閉層的浮動(dòng)層插件
- jQuery實(shí)現(xiàn)單擊按鈕遮罩彈出對(duì)話框(仿天貓的刪除對(duì)話框)
- 基于Jquery的仿Windows Aero彈出窗(漂亮的關(guān)閉按鈕)
- jquery實(shí)現(xiàn)界面點(diǎn)擊按鈕彈出懸浮框
相關(guān)文章
jQuery動(dòng)態(tài)添加 input type=file的實(shí)現(xiàn)代碼
有時(shí)候需要在頁(yè)面上允許用戶上傳多個(gè)文件,個(gè)數(shù)由用戶自己決定,個(gè)數(shù)多了也可以刪除,使用jQuery可以很簡(jiǎn)單的實(shí)現(xiàn)這個(gè)功能2012-06-06
jQuery實(shí)現(xiàn)預(yù)加載圖片的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)預(yù)加載圖片的方法,涉及jQuery操作img的src屬性使用技巧,需要的朋友可以參考下2015-03-03
jQuery獲取節(jié)點(diǎn)和子節(jié)點(diǎn)文本的方法
本節(jié)主要介紹了jQuery如何獲取節(jié)點(diǎn)和子節(jié)點(diǎn)文本,下面有個(gè)示例,大家可以參考下2014-07-07
jQuery學(xué)習(xí)筆記之jQuery原型屬性和方法
這篇文章主要介紹了jQuery原型屬性和方法,,需要的朋友可以參考下2014-06-06
jQuery獲取Radio,CheckBox選擇的Value值(示例代碼)
這篇文章主要是對(duì)jQuery獲取Radio,CheckBox選擇的Value值進(jìn)行了詳細(xì)的介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12
jquery input checked全選與反選1.3.2的版本
jquery 全選與反選1.3.2的版本2009-05-05
jquery實(shí)現(xiàn)垂直無(wú)限輪播的方法分析
這篇文章主要介紹了jquery實(shí)現(xiàn)垂直無(wú)限輪播的方法,結(jié)合實(shí)例形式分析了jQuery無(wú)限輪播相關(guān)界面布局、樣式與頁(yè)面元素動(dòng)態(tài)操作實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-07-07
jQuery實(shí)現(xiàn)的自定義彈出層效果實(shí)例詳解
這篇文章主要介紹了jQuery實(shí)現(xiàn)的自定義彈出層效果,結(jié)合實(shí)例形式較為詳細(xì)的分析了jQuery自定義彈出層的布局、事件響應(yīng)與頁(yè)面元素動(dòng)態(tài)操作的相關(guān)技巧,需要的朋友可以參考下2016-09-09
jquery+json 通用三級(jí)聯(lián)動(dòng)下拉列表
用Jquery實(shí)現(xiàn),原始代碼只支持IE,這里我改了一下,我的代碼里面有三個(gè)版本的實(shí)現(xiàn)2010-04-04
jquery+swiper組件實(shí)現(xiàn)時(shí)間軸滑動(dòng)年份tab切換效果
這篇文章主要介紹了jquery+swiper組件實(shí)現(xiàn)時(shí)間軸滑動(dòng)年份tab切換效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12

