基于Jquery的开发个代阴影的对话框效果代码

时间:2021-05-25

复制代码 代码如下:
<script type="text/javascript" src="http://img.zzl.com/script/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function() {
$("#open").click(function() {
openDialog(a1); //调用,直接写上DIV的ID即可
});
});
var openDialog = function(o) {
var dialog = new zzlDialog(o);
dialog.open();
}
var zzlDialog = function(o) {
this.init = function() {

var XBox = '\
<div id="mask"/>\
<div id="wai">\
</div>\
<div id="nie">\
<table>\
<thead>\
<tr>\
<td>\
阴影弹出框\
</td>\
<td>\
</td>\
</tr>\
</thead>\
<tbody>\
<tr>\
<td colspan="2">' + $(o).html() + '\
</td>\
</tr>\
</tbody>\
</table>\
</div>\
';
$(document.body).append(XBox);
};

this.cssInit = function() {

$("#wai").css({ "padding": "10px", "background": "#000", "filter": "Alpha(Opacity='50')", "position": "absolute" });
$("#nie").css({ "position": "absolute", "z-index": "1000" });
$("#nie>table").css({ "border": "1px solid rgb(55,119,188)", "border-collapse": "collapse", "background": "#fff" });
$("#nie>table>thead>tr").css({ "background": "rgb(0,94,172)", "color": "#fff", "height": "30px", "font-size": "14px", "font-weight": "bold" });
$("#nie>table").find("td").css({ "padding": "5"});

$("#nie").css({ "top": "50px" });
$("#nie").css({ "left": "50px" });

var $close = $("#nie>table>thead").find("td").next("td");
$close.html("<span>关闭</span>");
$close.css({ "text-align": "right", "padding-right": "5px" });
$close.find("span").css({ "font-weight": "normal", "cursor": "hand" });
$close.find("span").click(function() { new zzlDialog().closes(); });

$("#wai").css({ "width": ($("#nie>table").width() + 16) + "px", "height": ($("#nie>table").height() + 16) + "px" });
$("#wai").css({ "top": $("#nie").position().top - 8 + "px", "left": $("#nie").position().left - 8 + "px", "z-index": $("#nie").css("z-index") });
// $("#wai").corner("5px"); //圆角
};
this.open = function() {
this.init();
this.cssInit();
this.shadow();
};
this.shadow = function() {
this.event_b_show();
if (window.attachEvent) {
window.attachEvent('onresize', this.event_b);
window.attachEvent('onscroll', this.event_b);
}
else {
window.addEventListener('resize', this.event_b, false);
window.addEventListener('scroll', this.event_b, false);
}
};

this.event_b = function() {
var oShadow = $('#mask');
if (oShadow.css("display") != "none") {
if (this.event_b_show) {
this.event_b_show();
}
}
};
this.closes = function() {
var oShadow = $('#mask');
oShadow.css({ 'display': 'none' });
$("#wai").remove();
$("#nie").remove();
};
this.event_b_show = function() {
var oShadow = $('#mask');
oShadow.css({ 'position': 'absolute', 'display': '', 'opacity': '0.1', 'filter': 'alpha(opacity=10)', 'background': '#000' });
var sClientWidth = parent ? parent.document.body.offsetWidth : document.body.offsetWidth;
var sClientHeight = parent ? parent.document.body.offsetHeight : document.body.offsetHeight;
var sScrollTop = parent ? (parent.document.body.scrollTop + parent.document.documentElement.scrollTop) : (document.body.scrollTop + document.documentElement.scrollTop);
oShadow.css({ 'top': '0px', 'left': '0px', 'width': sClientWidth + "px", 'height': (sClientHeight + sScrollTop) + "px" });

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章