欢迎来到.net学习网

欢迎联系站长一起更新本网站!QQ:879621940

您当前所在位置:首页 » Html » 正文

热门阅读

div+javascript实现半透明遮盖层

创建时间:2011年07月23日 11:02  阅读次数:(9559)
分享到:
div+javascript实现半透明遮盖层
效果:点击按钮页面中间弹出一个div,div下面的页面不可操作。
全部源码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" >
<head >
<style type="text/css" >
/* LoginUI*/
.hidden { display: none;}
.popup{position: absolute;width: 450px; z-index: 60000;}
.container{ border: 5px solid #333;width: 445px;background: white;height:400px;}
</style >
<script type="text/javascript" >
var LoginUI = !!window.LoginUI || {};
$ = function(id){return document.getElementById(id)}
LoginUI.getViewportWidth = function(){
var width=0;
if(document.documentElement && document.documentElement.clientWidth){
width=document.documentElement.clientWidth;}
else if(document.body && document.body.clientWidth){
width=document.body.clientWidth;}
else if(window.innerWidth){
width=window.innerWidth-18;}
return width;
}
LoginUI.getViewportHeight = function() {
var height=0;
if(window.innerHeight){
height=window.innerHeight-18;}
else if(document.documentElement&&document.documentElement.clientHeight){
height=document.documentElement.clientHeight;}
else if(document.body&&document.body.clientHeight){
height=document.body.clientHeight;}
return height;
}
LoginUI.getViewportScrollY=function() {
var scrollY=0;
if(document.documentElement&&document.documentElement.scrollTop){
scrollY=document.documentElement.scrollTop;}
else if(document.body&&document.body.scrollTop){
scrollY=document.body.scrollTop;}
else if(window.pageYOffset){
scrollY=window.pageYOffset;}
else if(window.scrollY){
scrollY=window.scrollY;}
return scrollY;
}


LoginUI.centerDiv = function(div)
{
var top=((LoginUI.getViewportHeight()-div.offsetHeight)/2);
if(top<0)top=10;
div.style.left=((LoginUI.getViewportWidth()-div.offsetWidth)/2)+"px";
div.style.top=top+LoginUI.getViewportScrollY()+"px";
}
LoginUI.showLogin = function()
{
$("Login").className = "popup container";
$("Login").style.display="block";
LoginUI.centerDiv($("Login"));
$("blockUI").style.display="block";
$("blockUI").style.height = LoginUI.getViewportHeight() + LoginUI.getViewportScrollY() + "px";
}
LoginUI.hideLogin = function()
{
$("blockUI").style.display="none";
$("Login").style.display="none";
}
</script >
</head >
<body >
<div id="blockUI" style="display: none; background-color: black; width: 100%; height: 1000px; position: absolute; left: 0px; top: 0px; z-index: 50000; -moz-opacity: 0.5; opacity: 0.5;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=50);-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(opacity=50)';filter:alpha(opacity=50);" onclick="return false" onmousedown="return false" onmousemove="return false" onmouseup="return false" ondblclick="return false" >
 
</div >
<div id="Login" class="popup container hidden" ><a href="#" onclick="LoginUI.hideLogin()"
                margin-top: -33px; margin-right: 10px;" >[关闭]</a ></div >
<input type="button" onclick="LoginUI.showLogin()" value="Login In" / >
</body >
</html >
来源:
说明:所有来源为 .net学习网的文章均为原创,如有转载,请在转载处标注本页地址,谢谢!
【编辑:Wyf

打赏

取消

感谢您的支持,我会做的更好!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

最新评论

共有评论0条
  • 暂无任何评论,请留下您对本文章的看法,共同参入讨论!
发表评论:
留言人:
内  容:
请输入问题 90+17=? 的结果(结果是:107)
结  果: