Home >Web Front-end >JS Tutorial >Modal div layer pop-up effect based on jquery_jquery

Modal div layer pop-up effect based on jquery_jquery

WBOY
WBOYOriginal
2016-05-16 18:21:051083browse

After many twists and turns, it was finally done. The rendering is as follows:
Modal div layer pop-up effect based on jquery_jquery
Specific implementation:
(1) Write the code of jquery.divbox.js:

Copy code The code is as follows:

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) Two js need to be referenced in the web page, jquery.divbox.js and jquery.js

(3) Test page code:
Copy code The code is as follows:


<머리>
测试



<스타일>
#divSCA
{
위치: 절대;
너비: 700px;
높이: 500px;
글꼴 크기: 12px;
배경: #fff;
테두리: 0px 솔리드 #000;
z-색인: 10001;
디스플레이: 없음;
}



<본문>

这是模态DIV,点击关闭



测试能否覆盖 선택




(4) 测试代码及源文件下载地址:

点击下载
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn