基本原理分析
Windows关机效果分析mCLLinux联盟
使用Windows系统的用户在关机的时候,出现的界面只允许用户选择关机、注销或取消动作,而桌面上的程序都不能使用,并且屏幕呈现灰色状态。
本例将仿照这种高亮显示的效果在网页上实现.
在网页上运用这种关机效果有什么好处呢?首先,由于单击某一链接后,将用户此时不可用的操作隐藏在后台,将可用的操作放在屏幕最上层,并高亮显示,可以避免用户的误操作。其次,将信息高亮显示,也可以提醒用户应该注意的事项。mCLLinux联盟
网页中实现关机效果分析mCLLinux联盟
在网页中实现这种效果的原理很简单。创建两个图层,一个为遮盖层,覆盖整个页面,并且显示为灰色;另一个图层作为高亮显示的部分,在遮盖层的上方,这可通过设置图层的z-index属性来设置。当取消关机效果后,只需将这两个图层元素在页面中删除即可。mCLLinux联盟
以下代码实现显示关机效果。mCLLinux联盟
<html> mCLLinux联盟
<head> mCLLinux联盟
<title>html" class="wordstyle">asp?typeid=119" snap_preview_added="no">Ajax LightBox Sample</title> mCLLinux联盟
<style type="text/html" class="wordstyle">asp?typeid=38" snap_preview_added="no">CSS"> mCLLinux联盟
#lightbox {/*该层为高亮显示层*/ mCLLinux联盟
BORDER-RIGHT: #fff 1px solid; mCLLinux联盟
BORDER-TOP: #fff 1px solid; mCLLinux联盟
DISPLAY: block; mCLLinux联盟
Z-INDEX: 9999; /*设置该层在网页的最上端,设置足够大*/ mCLLinux联盟
BACKGROUND: #fdfce9; /*设置背景色*/ mCLLinux联盟
LEFT: 50%; mCLLinux联盟
MARGIN: -220px 0px 0px -250px; mCLLinux联盟
BORDER-LEFT: #fff 1px solid; mCLLinux联盟
WIDTH: 500px; mCLLinux联盟
BORDER-BOTTOM: #fff 1px solid; mCLLinux联盟
POSITION: absolute; mCLLinux联盟
TOP: 50%; mCLLinux联盟
HEIGHT: 400px; mCLLinux联盟
TEXT-ALIGN: left mCLLinux联盟
} mCLLinux联盟
#overlay {/*该层为覆盖层*/ mCLLinux联盟
DISPLAY: block; mCLLinux联盟
Z-INDEX: 9998; /*设置高亮层的下方*/ mCLLinux联盟
FILTER: alpha(opacity=80); /*设置成透明*/ mCLLinux联盟
LEFT: 0px; mCLLinux联盟
WIDTH: 100%; mCLLinux联盟
POSITION: absolute; mCLLinux联盟
TOP: 0px; mCLLinux联盟
HEIGHT: 100%; mCLLinux联盟
BACKGROUND-COLOR: #000; mCLLinux联盟
moz-opacity: 0.8; mCLLinux联盟
opacity: .80 mCLLinux联盟
} mCLLinux联盟
</style> mCLLinux联盟
</head> mCLLinux联盟
<body> mCLLinux联盟
<!--该层为覆盖层 --> mCLLinux联盟
<div id="overlay"></div> mCLLinux联盟
<!--该层为高亮显示层 --> mCLLinux联盟
<div id="lightbox"></div> mCLLinux联盟
</body> mCLLinux联盟
</html>
mCLLinux联盟
需要注意的是,在IE浏览器中如果有<select>标记,则该标记不能被覆盖层覆盖,但在其他浏览器中则可以覆盖。 在使用IE浏览器时,要先将网页中的<select>元素隐藏起来。如以下代码可以用于隐藏页面所有的<select>元素。mCLLinux联盟
selects = document.getElementsByTagName('select');mCLLinux联盟
for(i = 0; i < selects.length; i++) { mCLLinux联盟
selects[i].style.visibility = visibility; mCLLinux联盟
}
代码实现mCLLinux联盟
客户端代码mCLLinux联盟
客户端的页面上有两个链接,用户单击链接后,向服务器端发送请求,并将返回信息显示到高亮层上。客户端的网页文件代码如下所示:mCLLinux联盟
<html> mCLLinux联盟
<head> mCLLinux联盟
<title>AJAX LightBox</title> mCLLinux联盟
<!-- 本例使用的css样式表文件--> mCLLinux联盟
<LINK href="lightbox.css" type=text/css rel=stylesheet> mCLLinux联盟
<!--prototype类文件--> mCLLinux联盟
<script type="text/html" class="wordstyle">asp?typeid=36" snap_preview_added="no">html" class="wordstyle">javascript"mCLLinux联盟
src="js/prototype.js" ></script> mCLLinux联盟
<!--本例使用的html" class="wordstyle">javascript代码--> mCLLinux联盟
<script type="text/html" class="wordstyle">javascript" src="lightbox.js" >mCLLinux联盟
</script> mCLLinux联盟
</head> mCLLinux联盟
<body> mCLLinux联盟
<DIV id=container> mCLLinux联盟
<UL> mCLLinux联盟
<LI><A class=lbOn href="getInfo.html" class="wordstyle">jsp?id=one">One</A> mCLLinux联盟
</LI> mCLLinux联盟
<LI><A class=lbOn href="getInfo.html" class="wordstyle">jsp?id=two">Two</A> mCLLinux联盟
</LI> mCLLinux联盟
</UL> mCLLinux联盟
</div> mCLLinux联盟
</body> mCLLinux联盟
</html>
另外,还需要设置该页面所使用CSS样式。lightbox.css样式表文件代码如下所示:mCLLinux联盟
#lightbox { mCLLinux联盟
BORDER-RIGHT: #fff 1px solid; mCLLinux联盟
BORDER-TOP: #fff 1px solid; mCLLinux联盟
DISPLAY: none; mCLLinux联盟
Z-INDEX: 9999; mCLLinux联盟
BACKGROUND: #fdfce9; mCLLinux联盟
LEFT: 50%; mCLLinux联盟
MARGIN: -220px 0px 0px -250px; mCLLinux联盟
BORDER-LEFT: #fff 1px solid; mCLLinux联盟
WIDTH: 500px; mCLLinux联盟
BORDER-BOTTOM: #fff 1px solid; mCLLinux联盟
POSITION: absolute; mCLLinux联盟
TOP: 50%; mCLLinux联盟
HEIGHT: 400px; mCLLinux联盟
TEXT-ALIGN: left mCLLinux联盟
} mCLLinux联盟
UNKNOWN { mCLLinux联盟
POSITION: fixed mCLLinux联盟
} mCLLinux联盟
#overlay { mCLLinux联盟
DISPLAY: none; mCLLinux联盟
Z-INDEX: 5000; FILTER: alpha(opacity=80); mCLLinux联盟
LEFT: 0px; mCLLinux联盟
WIDTH: 100%; mCLLinux联盟
POSITION: absolute; mCLLinux联盟
TOP: 0px; mCLLinux联盟
HEIGHT: 100%; mCLLinux联盟
BACKGROUND-COLOR: #000; moz-opacity: 0.8; opacity: .80 mCLLinux联盟
} mCLLinux联盟
UNKNOWN { mCLLinux联盟
POSITION: fixed mCLLinux联盟
} mCLLinux联盟
.done#lightbox #lbLoadMessage { mCLLinux联盟
DISPLAY: none mCLLinux联盟
} mCLLinux联盟
.done#lightbox #lbContent { mCLLinux联盟
DISPLAY: block mCLLinux联盟
} mCLLinux联盟
.loading#lightbox #lbContent { mCLLinux联盟
DISPLAY: none mCLLinux联盟
} mCLLinux联盟
.loading#lightbox #lbLoadMessage { mCLLinux联盟
DISPLAY: block mCLLinux联盟
} mCLLinux联盟
.done#lightbox IMG { mCLLinux联盟
WIDTH: 100%; HEIGHT: 100% mCLLinux联盟
}
客户端脚本mCLLinux联盟
由于浏览器对图层的支持不同,所以首先要确定客户端浏览器的类型。以下代码可用于判断客户端的浏览器和html" class="wordstyle">asp"
snap_preview_added="no">操作系统。 mCLLinux联盟
var detect = navigator.userAgent.toLowerCase(); mCLLinux联盟
var OS,browser,version,total,thestring; mCLLinux联盟
function getBrowserInfo() { mCLLinux联盟
if (checkIt('konqueror')) { mCLLinux联盟
browser = "Konqueror"; mCLLinux联盟
OS = "html" class="wordstyle">asp?typeid=60" snap_preview_added="no">Linux"; mCLLinux联盟
} mCLLinux联盟
else if (checkIt('safari')) browser = "Safari" mCLLinux联盟
else if (checkIt('omniWeb')) browser = "OmniWeb" mCLLinux联盟
else if (checkIt('opera')) browser = "Opera" mCLLinux联盟
else if (checkIt('Webtv')) browser = "WebTV"; mCLLinux联盟
else if (checkIt('icab')) browser = "iCab" mCLLinux联盟
else if (checkIt('msie')) browser = "Internet Explorer" mCLLinux联盟
else if (!checkIt('compatible')) { mCLLinux联盟
browser = "Netscape Navigator" mCLLinux联盟
version = detect.charAt(8); mCLLinux联盟
} mCLLinux联盟
else browser = "An unknown browser"; mCLLinux联盟
if (!version) version = detect.charAt(place + thestring.length); mCLLinux联盟
if(!OS) { mCLLinux联盟
if (checkIt('linux')) OS = "Linux"; mCLLinux联盟
else if (checkIt('x11')) OS = "Unix"; mCLLinux联盟
else if (checkIt('mac')) OS = "Mac" mCLLinux联盟
else if (checkIt('win')) OS = "Windows" mCLLinux联盟
else OS = "an unknown operating system"; mCLLinux联盟
} mCLLinux联盟
} mCLLinux联盟
function checkIt(string) { mCLLinux联盟
place = detect.indexOf(string) + 1; mCLLinux联盟
thestring = string; mCLLinux联盟
return place; mCLLinux联盟
} mCLLinux联盟
下面看一下网页加载时需要添加的方法。有关网页加载和初始化方法代码如下: mCLLinux联盟
//网页加载调用initialize和getBrowserInfo方法 mCLLinux联盟
Event.observe(window, 'load', initialize, false); mCLLinux联盟
Event.observe(window, 'load', getBrowserInfo, false); mCLLinux联盟
//未加载时清空缓存 mCLLinux联盟
Event.observe(window, 'unload', Event.unloadCache, false); mCLLinux联盟
//初始化方法 mCLLinux联盟
function initialize(){ mCLLinux联盟
//调用该方法为该页添加覆盖层和高亮显示层 mCLLinux联盟
addLightboxMarkup(); mCLLinux联盟
//为每个可高亮显示的元素创建lightbox对象 mCLLinux联盟
lbox = document.getElementsByClassName('lbOn'); mCLLinux联盟
for(i = 0; i < lbox.length; i++) { mCLLinux联盟
valid = new lightbox(lbox[i]); mCLLinux联盟
} mCLLinux联盟
} mCLLinux联盟
// 使用Dom方法创建覆盖层和高亮层 mCLLinux联盟
function addLightboxMarkup() { mCLLinux联盟
bod = document.getElementsByTagName('body')[0]; mCLLinux联盟
overlay = document.createElement('div'); mCLLinux联盟
overlay.id = 'overlay'; mCLLinux联盟
lb = document.createElement('div'); mCLLinux联盟
lb.id = 'lightbox'; mCLLinux联盟
lb.className = 'loading'; mCLLinux联盟
lb.innerHTML = '<div id="lbLoadMessage">' + mCLLinux联盟
'<p>Loading</p>' + mCLLinux联盟
'</div>'; mCLLinux联盟
bod.appendChild(overlay); mCLLinux联盟
bod.appendChild(lb); mCLLinux联盟
} mCLLinux联盟
封装lightbox类 mCLLinux联盟
初始化数据时,为每个可高亮显示的链接创建了lightbox对象。该类的代码具体实现如下: mCLLinux联盟
var lightbox = Class.create(); mCLLinux联盟
lightbox.prototype = { mCLLinux联盟
yPos : 0, mCLLinux联盟
xPos : 0, mCLLinux联盟
//构造方法,ctrl为创建该对象的元素 mCLLinux联盟
initialize: function(ctrl) { mCLLinux联盟
//将该元素的链接赋值给this.content mCLLinux联盟
this.content = ctrl.href; mCLLinux联盟
//为该元素添加onclick事件activate方法 mCLLinux联盟
Event.observe(ctrl, 'click', this.activate.bindAsEventListener(this), false); mCLLinux联盟
ctrl.onclick = function(){return false;}; mCLLinux联盟
}, mCLLinux联盟
//当单击链接时 mCLLinux联盟
activate: function(){ mCLLinux联盟
if (browser == 'Internet Explorer'){//判断为IE浏览器 mCLLinux联盟
this.getScroll(); mCLLinux联盟
this.prepareIE('100%', 'hidden'); mCLLinux联盟
this.setScroll(0,0); mCLLinux联盟
this.hideSelects('hidden');//隐藏所有的<select>标记 mCLLinux联盟
} mCLLinux联盟
//调用该类中的displayLightbox方法 mCLLinux联盟
this.displayLightbox("block"); mCLLinux联盟
}, mCLLinux联盟
prepareIE: function(height, overflow){ mCLLinux联盟
bod = document.getElementsByTagName('body')[0]; mCLLinux联盟
bod.style.height = height; mCLLinux联盟
bod.style.overflow = overflow; mCLLinux联盟
mCLLinux联盟
htm = document.getElementsByTagName('html')[0]; mCLLinux联盟
htm.style.height = height; mCLLinux联盟
htm.style.overflow = overflow; mCLLinux联盟
}, mCLLinux联盟
hideSelects: function(visibility){ mCLLinux联盟
selects = document.getElementsByTagName('select'); mCLLinux联盟
for(i = 0; i < selects.length; i++) { mCLLinux联盟
selects[i].style.visibility = visibility; mCLLinux联盟
} mCLLinux联盟
}, mCLLinux联盟
getScroll: function(){ mCLLinux联盟
if (self.pageYOffset) { mCLLinux联盟
this.yPos = self.pageYOffset; mCLLinux联盟
} else if (document.documentElement && document.documentElement.scrollTop){ mCLLinux联盟
this.yPos = document.documentElement.scrollTop; mCLLinux联盟
} else if (document.body) { mCLLinux联盟
this.yPos = document.body.scrollTop; mCLLinux联盟
} mCLLinux联盟
}, mCLLinux联盟
setScroll: function(x, y){ mCLLinux联盟
window.scrollTo(x, y); mCLLinux联盟
}, mCLLinux联盟
displayLightbox: function(display){ mCLLinux联盟
//将覆盖层显示 mCLLinux联盟
$('overlay').style.display = display; mCLLinux联盟
//将高亮层显示 mCLLinux联盟
$('lightbox').style.display = display; mCLLinux联盟
//如果不是隐藏状态,则调用该类中的loadInfo方法 mCLLinux联盟
if(display != 'none') this.loadInfo(); mCLLinux联盟
}, mCLLinux联盟
//该方法发送Ajax请求 mCLLinux联盟
loadInf function() { mCLLinux联盟
//当请求完成后调用本类中processInfo方法 mCLLinux联盟
var myAjax = new Ajax.Request( mCLLinux联盟
this.content, mCLLinux联盟
{method: 'get', parameters: "", onComplete: this.processInfo.bindAsEvent Listener (this)} mCLLinux联盟
); mCLLinux联盟
}, mCLLinux联盟
// 将返回的文本信息显示到高亮层上 mCLLinux联盟
processInf function(response){ mCLLinux联盟
//获得返回的文本数据 mCLLinux联盟
var result = response.responseText; mCLLinux联盟
//显示到高亮层 mCLLinux联盟
info = "<div id='lbContent'>" + result + "</div>"; mCLLinux联盟
//在info元素前插入一个元素 mCLLinux联盟
new Insertion.Before($('lbLoadMessage'), info) mCLLinux联盟
//改变该元素的class name的值 mCLLinux联盟
$('lightbox').className = "done"; mCLLinux联盟
//调用本类中actions方法 mCLLinux联盟
this.actions(); mCLLinux联盟
var ctrl=$('lightbox'); mCLLinux联盟
//为高亮层添加事件处理方法reset mCLLinux联盟
Event.observe(ctrl, 'click', this.reset.bindAsEventListener(this), false); mCLLinux联盟
ctrl.onclick = function(){return false;}; mCLLinux联盟
}, mCLLinux联盟
//恢复初始状态 mCLLinux联盟
reset:function(){ mCLLinux联盟
//隐藏覆盖层 mCLLinux联盟
$('overlay').style.display="none"; mCLLinux联盟
//清空返回数据 mCLLinux联盟
$('lbContent').innerHTML=""; mCLLinux联盟
//隐藏高亮层 mCLLinux联盟
$('lightbox').style.display="none"; mCLLinux联盟
}, mCLLinux联盟
// Search through new links within the lightbox, and attach click event mCLLinux联盟
actions: function(){ mCLLinux联盟
lbActions = document.getElementsByClassName('lbAction'); mCLLinux联盟
for(i = 0; i < lbActions.length; i++) { mCLLinux联盟
Event.observe(lbActions[i], 'click', this[lbActions[i].rel].bindAs EventListener(this), false); mCLLinux联盟
lbActions[i].onclick = function(){return false;}; mCLLinux联盟
} mCLLinux联盟
} mCLLinux联盟
}
提示:由于该对象比较复杂,读者可以仔细参阅代码的注释部分。
服务器端代码
服务器端首先获得查询中的“id”值,如果该值为null或为空,则设置为默认值。然后
判断该值,并且返回相应的一段字符串信息。处理请求的getInfohtml" class="wordstyle">jsp页面代码如下:mCLLinux联盟
<%@ page language="java" import="java.util.*"%> mCLLinux联盟
<% mCLLinux联盟
//获得请求中id的值 mCLLinux联盟
String imgID = request.getParameter("id"); mCLLinux联盟
if (imgID==null||imgID.equals(""))//如果为null或为空 mCLLinux联盟
imgID="one";//设定为默认值 mCLLinux联盟
if ( imgID.equals("one"))//如果为one mCLLinux联盟
{ mCLLinux联盟
%> mCLLinux联盟
<h3 id="cartitle" style="border-bottom: 1px solid #C0C0C0; margin-bottom: -5px">Porsche Carrera GT</h3> mCLLinux联盟
<p>The Carrera GT has a 5.7 litre V10 internal combustion engine that produces mCLLinux联盟
605 SAE horsepower (451 kW). Porsche claims it will accelerate from 0 to 100 mCLLinux联盟
km/h (62 mph) in 3.9 seconds and has a maximum speed of 330 km/h (204 mph). mCLLinux联盟
With 605 hp, the car weighs 1,380 kg (3,042 lb). The Carrera GT is only mCLLinux联盟
offered with a six-speed manual transmission, in contrast to its rival the mCLLinux联盟
Ferrari Enzo that is only offered with sequential manual transmission. Also mCLLinux联盟
the Carrera GT is significantly less expensive than the Ferrari Enzo. The mCLLinux联盟
Ferrari Enzo is priced around $660,000 to the Carrera GT's $440,000. The mCLLinux联盟
Carrera GT is known for its high quality and reliability which makes it one of mCLLinux联盟
the best supercars ever. mCLLinux联盟
<%}else{//否则 mCLLinux联盟
%> mCLLinux联盟
<h3 id="cartitle" style="border-bottom: 1px solid #C0C0C0; margin-bottom: -5px">Ferrari Testarossa</h3> mCLLinux联盟
<p>The Ferrari Testarossa is an V12 mid-engined sports car made by Ferrari. mCLLinux联盟
The name, which means "red head", comes from the red painted cylinder heads on mCLLinux联盟
the flat-12 engine. The engine was technically a 180?V engine since it shared mCLLinux联盟
flat-plane crankshaft pins with opposing cylinders. Output was 390 hp (291 mCLLinux联盟
kW), and the car won many comparison tests and admirers - it was featured on mCLLinux联盟
the cover of Road & Track magazine nine times in just five years. Almost mCLLinux联盟
10,000 Testarossas, 512TRs, and 512Ms were produced, making this one of the mCLLinux联盟
most common Ferrari models despite its high price and exotic design. mCLLinux联盟
<%}%> mCLLinux联盟
html" class="wordstyle">aspx" snap_preview_added="spa" snap_icon_added="spa" ac
t_suffix icon_trigger="false" text_trigger="true" parent_link_icon="false">
http://blog.csdn.net/danforn/archive/2007/03/09/1525255.html" class="wordstyle">
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论