您的位置:首页 > Web前端 > JavaScript

JavaScript实现背景变暗,弹出提示层(类似关机效果)

2010-08-12 23:21 956 查看
Windows关机效果分析
使用Windows系统的用户在关机的时候,出现的界面只允许用户选择关机、注销或取消动作,而桌面上的程序都不能使用,并且屏幕呈现灰色状态。

本例将仿照这种高亮显示的效果在网页上实现.

在网页上运用这种关机效果有什么好处呢?首先,由于单击某一链接后,将用户此时不可用的操作隐藏在后台,将可用的操作放在屏幕最上层,并高亮显示,可以避免用户的误操作。其次,将信息高亮显示,也可以提醒用户应该注意的事项。
网页中实现关机效果分析
在网页中实现这种效果的原理很简单。创建两个图层,一个为遮盖层,覆盖整个页面,并且显示为灰色;另一个图层作为高亮显示的部分,在遮盖层的上方,这可通过设置图层的z-index属性来设置。当取消关机效果后,只需将这两个图层元素在页面中删除即可。
以下代码实现显示关机效果。

 

代码:

 

<html>
<head>
</head>
<body>
<p align="center">
<script>
function locking(){
    document.all.ly.style.display="block";
    document.all.ly.style.width=document.body.clientWidth;
    document.all.ly.style.height=document.body.clientHeight;
    document.all.Layer2.style.display='block';
}
function Lock_CheckForm(theForm){
    if(theForm.P_USERPASS.value==''){alert("错误:请输入你的用户密码!");theForm.P_USERPASS.focus();return false;}
    if(theForm.P_USERPASS.value !='123'){alert("错误:密码错误!");theForm.P_USERPASS.value=''; theForm.P_USERPASS.focus();return false;}
    else{document.all.ly.style.display='none';document.all.Layer2.style.display='none';}
    return false;
}
</script>
<img src="http://gg.blueidea.com/2006/chinaok/468x60.gif">

</p>
<p align="center">

<INPUT TYPE="button" value="系统锁定" onclick="locking()">
</p>
<div id="ly" style="position:absolute;top:0px;FILTER: alpha(opacity=30);background-color:#777; z-index:2; left: 0px;display:none;"> </div>

<!--   浮层框架开始   -->
      <div id="Layer2" align="center" style="position:absolute; z-index:3; width: 540; height:170px;left:expression((document.body.offsetWidth-540)/2); top: expression((document.body.offsetHeight-170)/2);background-color:#fff;display:none;" valign="center">  
<form method="POST" action="" onsubmit="return Lock_CheckForm(this);">
<TABLE width=540 height=170 border=0 cellpadding=0 cellspacing=0 style="border:0 solid #e7e3e7;border-collapse: collapse">
    <TR>
         <TD style="background-color:#73A2d6;color:#fff;padding-left:4px;padding-top:2px;font-weight:bold;font-size:14px;" height=27 valign="center">[ 警 告 ]</TD>
    </TR>
    <TR>
         <TD align="center" valign="center">请输入解除锁定密码<p><input type="text" name="P_USERPASS" size="20"></TD>
    </TR>
    <TR>
        <TD height=30 align="center"><INPUT type="submit" value="   确   定   "></TD>
    </TR>
</TABLE>
</form>
      </div>  
<!--   浮层框架结束   -->
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐