经过几多周折,终于搞出来了,效果图如下:
具体实现:
(1) 编写 jquery.divbox.js 的代码:
复制代码 代码如下:
jQuery.fn.extend(
{
OpenDiv: function()
{
var sWidth, sHeight;
sWidth = window.screen.availWidth;
if (window.screen.availHeight > document.body.scrollHeight)
{
sHeight = window.screen.availHeight;
} else
{
sHeight = document.body.scrollHeight + 20;
}
var maskObj = document.createElement("div");
maskObj.setAttribute('id', 'BigDiv');
maskObj.style.position = "absolute";
maskObj.style.top = "0";
maskObj.style.left = "0";
maskObj.style.background = "#111";
maskObj.style.filter = "Alpha(opacity=70);";
maskObj.style.opacity = "0.7";
maskObj.style.width = sWidth + "px";
maskObj.style.height = sHeight + "px";
maskObj.style.zIndex = "10000";
$("body").attr("scroll", "no");
document.body.appendChild(maskObj);
$("#BigDiv").data("divbox_selectlist", $("select:visible"));
$("select:visible").hide();
$("#BigDiv").attr("divbox_scrolltop", $.ScrollPosition().Top);
$("#BigDiv").attr("divbox_scrollleft", $.ScrollPosition().Left);
$("#BigDiv").attr("htmloverflow", $("html").css("overflow"));
$("html").css("overflow", "hidden");
window.scrollTo($("#BigDiv").attr("divbox_scrollleft"), $("#BigDiv").attr("divbox_scrolltop"));
var MyDiv_w = this.width();
var MyDiv_h = this.height();
MyDiv_w = parseInt(MyDiv_w);
MyDiv_h = parseInt(MyDiv_h);
var width = $.PageSize().Width;
var height = $.PageSize().Height;
var left = $.ScrollPosition().Left;
var top = $.ScrollPosition().Top;
var Div_topposition = top + (height / 2) - (MyDiv_h / 2);
var Div_leftposition = left + (width / 2) - (MyDiv_w / 2);
this.css("position", "absolute");
this.css("z-index", "10001");
this.css("background", "#fff");
this.css("left", Div_leftposition + "px");
this.css("top", Div_topposition + "px");
if ($.browser.mozilla)
{
this.show();
return;
}
this.fadeIn("fast");
}
, CloseDiv: function()
{
if ($.browser.mozilla)
{
this.hide();
} else
{
this.fadeOut("fast");
} $("html").css("overflow", $("#BigDiv").attr("htmloverflow"));
window.scrollTo($("#BigDiv").attr("divbox_scrollleft"), $("#BigDiv").attr("divbox_scrolltop"));
$("#BigDiv").data("divbox_selectlist").show();
$("#BigDiv").remove();
}
});
$.extend(
{
PageSize:function ()
{
var width=0;
var height=0;
width=window.innerWidth!=null?window.innerWidth:document.documentElement&&document.documentElement.clientWidth?document.documentElement.clientWidth:document.body!=null?document.body.clientWidth:null;
height=window.innerHeight!=null?window.innerHeight:document.documentElement&&document.documentElement.clientHeight?document.documentElement.clientHeight:document.body!=null?document.body.clientHeight:null;
return {Width:width,Height:height};
}
,ScrollPosition:function ()
{
var top=0,left=0;
if($.browser.mozilla)
{
top=window.pageYOffset;
left=window.pageXOffset;
}
else if($.browser.msie)
{
top=document.documentElement.scrollTop;
left=document.documentElement.scrollLeft;
}
else if(document.body)
{
top=document.body.scrollTop;
left=document.body.scrollLeft;
}
return {Top:top,Left:left};
}
});
(2) 网页中需引用两个js, jquery.divbox.js 和 jquery.js
(3) 测试页面代码:
复制代码 代码如下:
<html>
<head>
<title>测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.js"><script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.divbox.js"><style>
#divSCA
{
position: absolute;
width: 700px;
height: 500px;
font-size: 12px;
background: #fff;
border: 0px solid #000;
z-index: 10001;
display: none;
}
</style>
<script type="text/javascript">
function openDiv() {
$("#divSCA").OpenDiv();
}
function closeDiv() {
$("#divSCA").CloseDiv();
}
</script>
</head>
<body>
<div id="divSCA">
<font size="50">这是模态DIV,点击关闭</font>
<input type="button" value="关闭" onclick="closeDiv()">
</div>
<input type="button" value="弹出" onclick="openDiv()"/>
测试能否覆盖 select
<select>
<option>测试1</option>
<option>测试2</option>
<option>测试3</option>
</select>
</body>
</html>
(4) 测试代码及源文件下载地址:
点击下载
具体实现:
(1) 编写 jquery.divbox.js 的代码:
复制代码 代码如下:
jQuery.fn.extend(
{
OpenDiv: function()
{
var sWidth, sHeight;
sWidth = window.screen.availWidth;
if (window.screen.availHeight > document.body.scrollHeight)
{
sHeight = window.screen.availHeight;
} else
{
sHeight = document.body.scrollHeight + 20;
}
var maskObj = document.createElement("div");
maskObj.setAttribute('id', 'BigDiv');
maskObj.style.position = "absolute";
maskObj.style.top = "0";
maskObj.style.left = "0";
maskObj.style.background = "#111";
maskObj.style.filter = "Alpha(opacity=70);";
maskObj.style.opacity = "0.7";
maskObj.style.width = sWidth + "px";
maskObj.style.height = sHeight + "px";
maskObj.style.zIndex = "10000";
$("body").attr("scroll", "no");
document.body.appendChild(maskObj);
$("#BigDiv").data("divbox_selectlist", $("select:visible"));
$("select:visible").hide();
$("#BigDiv").attr("divbox_scrolltop", $.ScrollPosition().Top);
$("#BigDiv").attr("divbox_scrollleft", $.ScrollPosition().Left);
$("#BigDiv").attr("htmloverflow", $("html").css("overflow"));
$("html").css("overflow", "hidden");
window.scrollTo($("#BigDiv").attr("divbox_scrollleft"), $("#BigDiv").attr("divbox_scrolltop"));
var MyDiv_w = this.width();
var MyDiv_h = this.height();
MyDiv_w = parseInt(MyDiv_w);
MyDiv_h = parseInt(MyDiv_h);
var width = $.PageSize().Width;
var height = $.PageSize().Height;
var left = $.ScrollPosition().Left;
var top = $.ScrollPosition().Top;
var Div_topposition = top + (height / 2) - (MyDiv_h / 2);
var Div_leftposition = left + (width / 2) - (MyDiv_w / 2);
this.css("position", "absolute");
this.css("z-index", "10001");
this.css("background", "#fff");
this.css("left", Div_leftposition + "px");
this.css("top", Div_topposition + "px");
if ($.browser.mozilla)
{
this.show();
return;
}
this.fadeIn("fast");
}
, CloseDiv: function()
{
if ($.browser.mozilla)
{
this.hide();
} else
{
this.fadeOut("fast");
} $("html").css("overflow", $("#BigDiv").attr("htmloverflow"));
window.scrollTo($("#BigDiv").attr("divbox_scrollleft"), $("#BigDiv").attr("divbox_scrolltop"));
$("#BigDiv").data("divbox_selectlist").show();
$("#BigDiv").remove();
}
});
$.extend(
{
PageSize:function ()
{
var width=0;
var height=0;
width=window.innerWidth!=null?window.innerWidth:document.documentElement&&document.documentElement.clientWidth?document.documentElement.clientWidth:document.body!=null?document.body.clientWidth:null;
height=window.innerHeight!=null?window.innerHeight:document.documentElement&&document.documentElement.clientHeight?document.documentElement.clientHeight:document.body!=null?document.body.clientHeight:null;
return {Width:width,Height:height};
}
,ScrollPosition:function ()
{
var top=0,left=0;
if($.browser.mozilla)
{
top=window.pageYOffset;
left=window.pageXOffset;
}
else if($.browser.msie)
{
top=document.documentElement.scrollTop;
left=document.documentElement.scrollLeft;
}
else if(document.body)
{
top=document.body.scrollTop;
left=document.body.scrollLeft;
}
return {Top:top,Left:left};
}
});
(2) 网页中需引用两个js, jquery.divbox.js 和 jquery.js
(3) 测试页面代码:
复制代码 代码如下:
<html>
<head>
<title>测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.js"><script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.divbox.js"><style>
#divSCA
{
position: absolute;
width: 700px;
height: 500px;
font-size: 12px;
background: #fff;
border: 0px solid #000;
z-index: 10001;
display: none;
}
</style>
<script type="text/javascript">
function openDiv() {
$("#divSCA").OpenDiv();
}
function closeDiv() {
$("#divSCA").CloseDiv();
}
</script>
</head>
<body>
<div id="divSCA">
<font size="50">这是模态DIV,点击关闭</font>
<input type="button" value="关闭" onclick="closeDiv()">
</div>
<input type="button" value="弹出" onclick="openDiv()"/>
测试能否覆盖 select
<select>
<option>测试1</option>
<option>测试2</option>
<option>测试3</option>
</select>
</body>
</html>
(4) 测试代码及源文件下载地址:
点击下载
标签:
模态div层
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“基于jquery的模态div层弹出效果”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。