用JavaScript实现仿Windows关机效果

JavaScript实现关机(附完整源码) 阅读详情

基本原理分析

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

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

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

 

在使用IE浏览器时,要先将网页中的<select>元素隐藏起来。如以下代码可以用于隐藏页面所有的<select>元素。
selects = document.getElementsByTagName('select');

 

代码实现
客户端代码
客户端的页面上有两个链接,用户单击链接后,向服务器端发送请求,并将返回信息显示到高亮层上。客户端的网页文件代码如下所示:

客户端脚本
由于浏览器对图层的支持不同,所以首先要确定客户端浏览器的类型。以下代码可用于判断客户端的浏览器和html" class="wordstyle">asp"

 

snap_preview_added="no">操作系统。
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
function getBrowserInfo() {
       if (checkIt('konqueror')) {
            browser = "Konqueror";
            OS = "html" class="wordstyle">asp?typeid=60" snap_preview_added="no">Linux";
       }
       else if (checkIt('safari')) browser = "Safari"
       else if (checkIt('omniWeb')) browser = "OmniWeb"
       else if (checkIt('opera')) browser = "Opera"
       else if (checkIt('Webtv')) browser = "WebTV";
       else if (checkIt('icab')) browser = "iCab"
       else if (checkIt('msie')) browser = "Internet Explorer"
       else if (!checkIt('compatible')) {
             browser = "Netscape Navigator"
            version = detect.charAt(8);
       }
       else browser = "An unknown browser";
       if (!version) version = detect.charAt(place + thestring.length);
       if(!OS) {
            if (checkIt('linux')) OS = "Linux";
            else if (checkIt('x11')) OS = "Unix";
            else if (checkIt('mac')) OS = "Mac"
            else if (checkIt('win')) OS = " Windows"
            else OS = "an unknown operating system";
       }
}
function checkIt(string) {
        place = detect.indexOf(string) + 1;
        thestring = string;
        return place;
}
下面看一下网页加载时需要添加的方法。有关网页加载和初始化方法代码如下:
//网页加载调用initialize和getBrowserInfo方法
Event.observe(window, 'load', initialize, false);
Event.observe(window, 'load', getBrowserInfo, false);
//未加载时清空缓存
Event.observe(window, 'unload', Event.unloadCache, false);
//初始化方法
function initialize(){
        //调用该方法为该页添加覆盖层和高亮显示层
        addLightboxMarkup();
        //为每个可高亮显示的元素创建lightbox对象
        lbox = document.getElementsByClassName('lbOn');
        for(i = 0; i < lbox.length; i++) {
                    valid = new lightbox(lbox[i]);
        }
}
// 使用Dom方法创建覆盖层和高亮层
function addLightboxMarkup() {
        bod = document.getElementsByTagName('body')[0];
        overlay = document.createElement('div');
        overlay.id = 'overlay';
        lb = document.createElement('div');
        lb.id = 'lightbox';
        lb.className = 'loading';
        lb.innerHTML = '<div id="lbLoadMessage">' +
                                           '<p>Loading</p>' +
                                           '</div>';
        bod.appendChild(overlay);
        bod.appendChild(lb);
}
封装lightbox类
初始化数据时,为每个可高亮显示的链接创建了lightbox对象。该类的代码具体实现如下:
var lightbox = Class.create();  
lightbox.prototype = {
       yPos : 0,
       xPos : 0,
      //构造方法,ctrl为创建该对象的元素
       initialize: function(ctrl) {
              //将该元素的链接赋值给this.content
              this.content = ctrl.href;
              //为该元素添加onclick事件activate方法
              Event.observe(ctrl, 'click', this.activate.bindAsEventListener(this), false);
              ctrl.onclick = function(){return false;};
       },
       //当单击链接时
       activate: function(){
              if (browser == 'Internet Explorer'){//判断为IE浏览器
                     this.getScroll();
                     this.prepareIE('100%', 'hidden');
                     this.setScroll(0,0);
                     this.hideSelects('hidden');//隐藏所有的<select>标记
              }
              //调用该类中的displayLightbox方法
              this.displayLightbox("block");
      },
      prepareIE: function(height, overflow){
            bod = document.getElementsByTagName('body')[0];
            bod.style.height = height;
            bod.style.overflow = overflow;
  
            htm = document.getElementsByTagName('html')[0];
            htm.style.height = height;
            htm.style.overflow = overflow; 
      },
      hideSelects: function(visibility){
           selects = document.getElementsByTagName('select');
           for(i = 0; i < selects.length; i++) {
                   selects[i].style.visibility = visibility;
            }
      },
      getScroll: function(){
            if (self.pageYOffset) {
                    this.yPos = self.pageYOffset;
            } else if (document.documentElement && document.documentElement.scrollTop){
                    this.yPos = document.documentElement.scrollTop; 
            } else if (document.body) {
                    this.yPos = document.body.scrollTop;
            }
      },
      setScroll: function(x, y){
            window.scrollTo(x, y); 
      },
      displayLightbox: function(display){
            //将覆盖层显示
            $('overlay').style.display = display;
            //将高亮层显示
            $('lightbox').style.display = display;
            //如果不是隐藏状态,则调用该类中的loadInfo方法
            if(display != 'none') this.loadInfo();
      },
      //该方法发送Ajax请求
      loadInf function() {
            //当请求完成后调用本类中processInfo方法
            var myAjax = new Ajax.Request(
          this.content,
          {method: 'get', parameters: "", onComplete: this.processInfo.bindAsEvent Listener (this)}
           );
      },
      // 将返回的文本信息显示到高亮层上
      processInf function(response){
           //获得返回的文本数据
           var result = response.responseText;
           //显示到高亮层
           info = "<div id='lbContent'>" + result + "</div>";
           //在info元素前插入一个元素
           new Insertion.Before($('lbLoadMessage'), info)
           //改变该元素的class name的值
           $('lightbox').className = "done"; 
           //调用本类中actions方法
           this.actions();
           var ctrl=$('lightbox');
           //为高亮层添加事件处理方法reset
          Event.observe(ctrl, 'click', this.reset.bindAsEventListener(this), false);
           ctrl.onclick = function(){return false;};
      },
      //恢复初始状态 
      reset:function(){
            //隐藏覆盖层
           $('overlay').style.display="none";
           //清空返回数据
            $('lbContent').innerHTML="";
            //隐藏高亮层
           $('lightbox').style.display="none";
     },
     // Search through new links within the lightbox, and attach click event
     actions: function(){
           lbActions = document.getElementsByClassName('lbAction');
           for(i = 0; i < lbActions.length; i++) {
                   Event.observe(lbActions[i], 'click', this[lbActions[i].rel].bindAs EventListener(this), false);
                   lbActions[i].onclick = function(){return false;};
           }
     }
}

 

提示:由于该对象比较复杂,读者可以仔细参阅代码的注释部分。

服务器端代码

服务器端首先获得查询中的“id”值,如果该值为null或为空,则设置为默认值。然后判断该值,并且返回相应的一段字符串信息。处理请求的getInfohtml" class="wordstyle">jsp页面代码如下:

<%@ page language="java" import="java.util.*"%>
<%
//获得请求中id的值
  String imgID = request.getParameter("id");
  if (imgID==null||imgID.equals(""))//如果为null或为空
      imgID="one";//设定为默认值
  if ( imgID.equals("one"))//如果为one
  {
%>
<h3 id="cartitle" style="border-bottom: 1px solid #C0C0C0; margin-bottom: -5px">Porsche Carrera GT</h3>
<p>The Carrera GT has a 5.7 litre V10 internal combustion engine that produces 
  605 SAE horsepower (451 kW). Porsche claims it will accelerate from 0 to 100 
  km/h (62 mph) in 3.9 seconds and has a maximum speed of 330 km/h (204 mph). 
  With 605 hp, the car weighs 1,380 kg (3,042 lb). The Carrera GT is only 
  offered with a six-speed manual transmission, in contrast to its rival the 
  Ferrari Enzo that is only offered with sequential manual transmission. Also 
  the Carrera GT is significantly less expensive than the Ferrari Enzo. The 
  Ferrari Enzo is priced around $660,000 to the Carrera GT's $440,000. The 
  Carrera GT is known for its high quality and reliability which makes it one of 
  the best supercars ever.
<%}else{//否则
%>
<h3 id="cartitle" style="border-bottom: 1px solid #C0C0C0; margin-bottom: -5px">Ferrari Testarossa</h3>
<p>The Ferrari Testarossa is an V12 mid-engined sports car made by Ferrari. 
  The name, which means &quot;red head&quot;, comes from the red painted cylinder heads on 
  the flat-12 engine. The engine was technically a 180?V engine since it shared 
  flat-plane crankshaft pins with opposing cylinders. Output was 390 hp (291 
  kW), and the car won many comparison tests and admirers - it was featured on 
  the cover of Road &amp; Track magazine nine times in just five years. Almost 
  10,000 Testarossas, 512TRs, and 512Ms were produced, making this one of the 
  most common Ferrari models despite its high price and exotic design.
<%}%>
html" class="wordstyle">aspx" snap_preview_added="spa" snap_icon_added="spa" act_suffix icon_trigger="false" text_trigger="true" parent_link_icon="false"> http://blog.youkuaiyun.com/danforn/archive/2007/03/09/1525255.html" class="wordstyle">

 

 

<html>
<head>
<title>AJAX LightBox</title>
<!-- 本例使用的css样式表文件-->
<LINK href="lightbox.css" type=text/css rel=stylesheet>
<!--prototype类文件-->
<script type="text/html" class="wordstyle">asp?typeid=36" snap_preview_added="no">html" class="wordstyle">javascript" src="js/prototype.js" ></script>
<!--本例使用的html" class="wordstyle">javascript代码-->
<script type="text/html" class="wordstyle">javascript" src="lightbox.js" ></script>
</head>
<body>
<DIV id=container>
<UL>
  <LI><A class=lbOn href="getInfo.html" class="wordstyle">jsp?id=one">One</A> 
  </LI>
  <LI><A class=lbOn href="getInfo.html" class="wordstyle">jsp?id=two">Two</A> 
  </LI>
</UL>
</div>
</body>
</html>

 

另外,还需要设置该页面所使用CSS样式。lightbox.css样式表文件代码如下所示:

 

#lightbox {
      BORDER-RIGHT: #fff 1px solid;
      BORDER-TOP: #fff 1px solid;
       DISPLAY: none; 
       Z-INDEX: 9999; 
       BACKGROUND: #fdfce9; 
       LEFT: 50%; 
       MARGIN: -220px 0px 0px -250px; 
       BORDER-LEFT: #fff 1px solid; 
       WIDTH: 500px; 
       BORDER-BOTTOM: #fff 1px solid; 
       POSITION: absolute; 
       TOP: 50%; 
       HEIGHT: 400px; 
       TEXT-ALIGN: left
}
UNKNOWN {
     POSITION: fixed
}
#overlay {
      DISPLAY: none;
      Z-INDEX: 5000; FILTER: alpha(opacity=80); 
      LEFT: 0px; 
      WIDTH: 100%; 
      POSITION: absolute; 
      TOP: 0px; 
      HEIGHT: 100%; 
      BACKGROUND-COLOR: #000; moz-opacity: 0.8; opacity: .80
}
UNKNOWN {
    POSITION: fixed
}
.done#lightbox #lbLoadMessage {
      DISPLAY: none
}
.done#lightbox #lbContent {
      DISPLAY: block
}
.loading#lightbox #lbContent {
      DISPLAY: none
}
.loading#lightbox #lbLoadMessage {
       DISPLAY: block
}
.done#lightbox IMG {
      WIDTH: 100%; HEIGHT: 100%
}

 

for(i = 0; i < selects.length; i++) {
       selects[i].style.visibility = visibility;
}

<html>
<head>
<title>html" class="wordstyle">asp?typeid=119" snap_preview_added="no">Ajax LightBox Sample</title>
<style type="text/html" class="wordstyle">asp?typeid=38" snap_preview_added="no">CSS">
#lightbox {/*该层为高亮显示层*/
       BORDER-RIGHT: #fff 1px solid;
       BORDER-TOP: #fff 1px solid;
       DISPLAY: block; 
       Z-INDEX: 9999; /*设置该层在网页的最上端,设置足够大*/
       BACKGROUND: #fdfce9; /*设置背景色*/
       LEFT: 50%; 
       MARGIN: -220px 0px 0px -250px; 
       BORDER-LEFT: #fff 1px solid; 
       WIDTH: 500px; 
       BORDER-BOTTOM: #fff 1px solid; 
       POSITION: absolute; 
       TOP: 50%; 
       HEIGHT: 400px; 
       TEXT-ALIGN: left
}
#overlay {/*该层为覆盖层*/
      DISPLAY: block;
      Z-INDEX: 9998; /*设置高亮层的下方*/
      FILTER: alpha(opacity=80); /*设置成透明*/
      LEFT: 0px; 
      WIDTH: 100%; 
      POSITION: absolute; 
      TOP: 0px; 
      HEIGHT: 100%; 
      BACKGROUND-COLOR: #000; 
      moz-opacity: 0.8; 
      opacity: .80
}
</style>
</head>
<body>
<!--该层为覆盖层 -->
<div id="overlay"></div>
<!--该层为高亮显示层 -->
<div id="lightbox"></div>
</body>
</html>

需要注意的是,在IE浏览器中如果有<select>标记,则该标记不能被覆盖层覆盖,但在其他浏览器中则可以覆盖。
 
Javascript实现控制系统关机和重启 (附完整源码) 阅读详情

相关推荐

JavaScript实现关机程序(附完整源码)

JavaScript实现关机程序(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 498

JavaScript控制系统关机和重启

js控制windows开关机 重启 function run(str){ try{ var objShell = new ActiveXObject(&quot;wscript.shell&quot;); objShell.Run(str); objShell=null; }catch(e){ tipAlert({&quot;title&quot;:&quot;提示&quot;,&quot;msg&amp

phs999的博客 6661

js仿Windows窗口

To make it easier for you, please have a look at ALL of the following samples. Most probably your upcoming question during developing with WinLIKE will be answered here. Please see the source code of the samples and the associated files to learn how you can define and use the many features of WinLIKE. Now move your mouse over the screenshots and get a short description of the samples. Then simply click to start. JS仿微软窗口效果

仿XP关机效果的弹出窗口(JS+样式实现)

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &

weixin_34129145的博客 123

使用javascript内置对象关闭计算机

sffffffffffffffffffffffffffffffffffffffsdfwfsdf

html+css+js仿windows桌面、windows窗口

用html、css、js实现的windows桌面和窗口。包括开始菜单、状态蓝、窗口等。和windows系统操作方法一样,如双击图标打开窗口,不用的窗口最小化到状态蓝,右击桌面图标可打开右键菜单。开始菜单中附件---游戏中有常见游戏。有适用万年历和设置壁纸功能。壁纸设置和windows设置壁纸一样。 你还可以自己新建新窗口,创建方法已封装好。可以自己修改开始菜单,桌面图标右键菜单。 窗口有最大化最小化还原功能。 每个窗口可以指向一个页面作为显示内容,可以做系统界面。 如果作为web项目主界面可以让用户像操作windows一样操作web程序。

仿windows关机对话框的提示框效果

网页特效观止|JsCode.CN|---仿windows关机对话框的提示框效果     function gourl(e){        switch(e){            case 1:                window.alert("点击了确定按钮.");                break;            case 2:               

橡皮擦 737

Js仿Windows窗口特效集锦

Js仿Windows窗口特效集锦 Js仿Windows窗口特效集锦 Js仿Windows窗口特效集锦

仿windows关机效果

这是仿Windows关机效果时的例子,效果图: Code<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/...

weixin_30624825的博客 115

漂亮的JS视窗(仿Windows窗口)

非常精致、非常漂亮的仿Windows的JS视窗特效,很专业,用到你的网站中一定会增色不少。

js 实现 关机特效(一)

js 实现 关机特效(一)! 值得下载看看!资源免费,大家分享!!

JavaScript仿Windows关机效果

基本原理分析Windows关机效果分析使用Windows系统的用户在关机的时候,出现的界面只允许用户选择关机、注销或取消动作,而桌面上的程序都不能使用,并且屏幕呈现灰色状态。本例将仿照这种高亮显示的效果在网页上实现.在网页上运用这种关机效果有什么好处呢?首先,由于单击某一链接后,将用户此时不可用的操作隐藏在后台,将可用的操作放在屏幕最上层,并高亮显示,可以避免用户的误操作。其次,将信息

Write One,Run Everywhere 835

XCP_Basic 移植步骤

XCP_Basic 移植步骤

ggzzc的博客 2316
上一篇: Asp编程实现计算页面执行时间
下一篇: Microsoft SQL Server 2005安装
xiaops2005
博客等级 码龄21年 10粉丝 16原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值