阿七
级别: 未验证会员
精华:
0
发帖: 909
威望: 0 点
金钱: 2161 RMB
贡献值: 0 点
在线时间:512(小时)
注册时间:2006-03-29
最后登录:2008-08-07
|
网页中多层效果的灵活使用
动态的网页技术(DHTM)已经非常普及,本文强力向大家推荐一段完整并且是经典的网页多层代码,适用于IE及NETSCAPE游览器,可实现完善的二层网页功能,具体代码请见面文后程序。 lIS`_H} \t)va:y 该段代码功能:打开该网页文件之后,将在正常的网页之上,浮动另外一层网页内容,可用鼠标随意移动第二层网页在第一层上的位置,并且当屏幕滚动时,第二图层可始终保持同第一图层的相对位置,效果非常好。 F oC
$X VxDIA_
@y 适用场合:有了这段代码,你可以对很多原有的网页进行改造,使游览者更为方便,比如可用于留言簿,第一层放置留言内容,浮动的第二层放置留言表单,这样游览留言操作和观察留言内容可在同一页面完成,并且无论屏幕滚动到什么位置,留言表单始终出现在屏幕之上,这无疑是最方便的留言系统工作方式。再比如可做为一般网页的导航条,有很多人为了编制美观的页面而放弃使用分栏导航页面方式,而使用整个页面,这样的页面每进入到一个分栏目,都要重新调入整个页面。有了这项技术,可以在原完整的页面之上,浮动一层导航菜单,即方便了导航又保持了页面的完整。另外也可以在某些页面之上浮动一个特定的图像或其它页面内容,等等,总之,这种技术应用非常广泛。 AuK$KGCI= %W9R08` 代码说明:代码段一可放置在网页的文件头处,即段。代码段二为正常的网页内容,即第一层的代码内容。第三段为第二层网页的代码段,即浮动的网页内容。代码段四为必要的控制代码,可放置在网页的最后处。灵活使用:下面的代码是完整的网页文件代码,把代码段二和代码段三换成你自己所需要的内容就可以了,但由于本网页文件涉及两个网页的制作过程,可能制作起来相当费力,并且很多网页制作工具不支持这一功能,用低级的网页工具存盘后将失去浮动效果,所以对于这样的网页最好的维护方法是分页维护,即分别编制两个完整的网页内容,之后按要求合并在一个网页文件内即可。这样向你介绍一种最可取的方法,众所周知,现在的网页技术可以实现在一个网页内调用其它网页的功能,即所谓的画中画功能,所以完全可以把代码二和代码三换成固定的调用其它网页的固定代码,之后只需要对这两个单独的页维护就可以了。具体可用下面的代码替换代码二和三: "
<+~u
z R/x3+_.f ILAYER id="ad1" visibility="hidden" height="60"> OGg\V
V' </ILAYER> p#jAEY p <NOLAYER> QP.Lq}
<IFRAME SRC="h1.htm" width="100%" height="60" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"> hhaiHi!$ </IFRAME> 其中SRC:用于指定打开的网页地址; T`wDdqWbEG width:该表格占用的宽度; 8)bR\s height:该表格点用的高度; }(8
>& marginwidth:网页内容在表格右侧的预留宽度; {)"[_< marginheight:网页内容在表格顶部预留的高度; y:98}gW`n hspace:网页右上角的横坐标; `sqr>QD vspace:网页右上角的纵坐标; 9no<;1+j, frameborder:是否显示边缘; ]uox ^HC scrolling:是否出现滚动条; E;CM"Y* 具体使用时把h1.htm分别换成不同的网页文件名。 ^%,{R},s
完成的网页文件代码如下: |\Jnr3) <html> QO}~"lMj <head> +o`%7r(R <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> nRc\!4 //代码段一 3[u-
LYW <style type="text/css"><!-- %urvX$r4K #floater {position: absolute;left: 500;top: 146;width: 125;visibility: visible;z-index: 10;} pFY*Y>6ar --> ?pZU'5le` </style> T"{~mQ* //代码段一结束 */h(4Hz <title>浮动层</title> %TQ4ZFD3 </head> |1!fuB A //代码段二(第一层内容,目前为空)
B1_9l3RM <body bgcolor="#FFFFFF"> y\^zxG*]' <BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR> 68,j~e3-i //代码段二结束 QD,m`7( //代码段三(浮动层内容,目前为一简单表格) ):PN0
.H8 <div ID="floater" style="left: 0px; top: 1px"> Y^Buz<OiG <table border="1" cellpadding="0" cellspacing="0" 0]7jb_n1 bgcolor="#25A78D" bordercolordark="#00FFFF" >KuNHuHu bordercolorlight="#000000"> A^,ul>! <tr> M
_<
|n <td>111<a href="file:///G:/C/NEW/dhtml2.htm">1111</a></td> ra*|HcLD <td>2222222</td> :epBd3f </tr> I*TTD]e'X </table> 8i]
S[$Fc </div> Zuzwc [Z1 //代码段三结束 xMk>r1Ud //代码段四 #WG}"[ ,c <script LANGUAGE="JavaScript"> {D8opepO) self.onError=null; ]vf_4QW= currentX = currentY = 0; >6Pe~J5,: whichIt = null; 4Mg%}/cC lastScrollX = 0; lastScrollY = 0; O8#]7\) NS = (document.layers) ? 1 : 0; n#"G)+h3# IE = (document.all) ? 1: 0; Me z&@{ <!-- STALKER CODE --> vWmt<E|e function heartBeat() { U:~]>B $ if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; } U~BR8]=G if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; } v @M6D} if(diffY != lastScrollY) { }0<2n~3P percent = .1 * (diffY - lastScrollY); TX YO{ if(percent > 0) percent = Math.ceil(percent); , SUx!o else percent = Math.floor(percent); V"8Go;[ if(IE) document.all.floater.style.pixelTop += percent; }#.OJub
if(NS) document.floater.top += percent; PSAEW.L lastScrollY = lastScrollY + percent; } [}Xw/@Uc; if(diffX != lastScrollX) {
T*B`8P percent = .1 * (diffX - lastScrollX); *lZ V3F if(percent > 0) percent = Math.ceil(percent); ,]JIp~=nsh else percent = Math.floor(percent); PfYeV/M| if(IE) document.all.floater.style.pixelLeft += percent; {TJ"O
if(NS) document.floater.left += percent; !b0A%1W; lastScrollX = lastScrollX + percent;}} P;XA|`& <!-- /STALKER CODE --> lhE]KdE3 <!-- DRAG DROP CODE --> Zd)LVc[ function checkFocus(x,y) { 7^.g\Kt? stalkerx = document.floater.pageX; ,,j> 2Ts stalkery = document.floater.pageY; [KGj70|~ stalkerwidth = document.floater.clip.width; oP7)
stalkerheight = document.floater.clip.height; &sn-;r if( (x > stalkerx && x < (stalkerx+stalkerwidth)) && (y > stalkery && y < (stalkery+stalkerheight))) return true; (@BB@G else return false; } j/wQ2"@a function grabIt(e) { RK&RMN8@ if(IE) {whichIt = event.srcElement; S_AN.8T while (whichIt.id.indexOf("floater") == -1) { u&`rK7J whichIt = whichIt.parentElement; /55 3v;l< if (whichIt == null) { return true; } } y9i+EV whichIt.style.pixelLeft = whichIt.offsetLeft; FFV
h~em{ whichIt.style.pixelTop = whichIt.offsetTop; ?:vB_@ currentX = (event.clientX + document.body.scrollLeft); >Wd=+$!I currentY = (event.clientY + document.body.scrollTop); } else { gi_f8RP=2a window.captureEvents(Event.MOUSEMOVE); 04X/(74 if(checkFocus (e.pageX,e.pageY)) { ZI :wJU:f whichIt = document.floater; qMqf7 . StalkerTouchedX = e.pageX-document.floater.pageX; ]xV2=!J StalkerTouchedY = e.pageY-document.floater.pageY; } } CF_2ez1u0y return true;} f0{tBD!% function moveIt(e) { u]3VK if (whichIt == null) { return false; } M~saYJio if(IE) { n5#9o},oK newX = (event.clientX + document.body.scrollLeft); i~DLo3 newY = (event.clientY + document.body.scrollTop); y.Yni*xt/ distanceX = (newX - currentX); distanceY = (newY - currentY); :?3y)*J! currentX = newX; currentY = newY; j{%'A whichIt.style.pixelLeft += distanceX; fdKTj
=4 whichIt.style.pixelTop += distanceY; =~$)Ieu if(whichIt.style.pixelTop < document.body.scrollTop) whichIt.style.pixelTop = document.body.scrollTop; q+67Wc= if(whichIt.style.pixelLeft < document.body.scrollLeft) whichIt.style.pixelLeft = document.body.scrollLeft; &nn+X%m9g if(whichIt.style.pixelLeft > document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20) whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20; EhIa31>X if(whichIt.style.pixelTop > document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5) whichIt.style.pixelTop = document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5; tjDCfJx* event.returnValue = false; 6~8X/
-02 } else { /5R?(- whichIt.moveTo(e.pageX-StalkerTouchedX,e.pageY-StalkerTouchedY); M|'![]-
if(whichIt.left < 0+self.pageXOffset) whichIt.left = 0+self.pageXOffset; 1GgG9I if(whichIt.top < 0+self.pageYOffset) whichIt.top = 0+self.pageYOffset; v<S?"#
]F= if( (whichIt.left + whichIt.clip.width) >= (window.innerWidth+ self.pageXOffset-17)) whichIt.left = ((window.innerWidth+self.pageXOffset)-whichIt.clip.width)-17; nTXM/ if( (whichIt.top + whichIt.clip.height) >= (window.innerHeight+ self.pageYOffset-17)) whichIt.top = ((window.innerHeight+self.pageYOffset)-whichIt.clip.height)-17; _sNJU
return false; } return false; } EAnw:yUV( function dropIt() { 'sAs# whichIt = null; zlN<yZB^ if(NS) window.releaseEvents (Event.MOUSEMOVE); x5nw/''[2 return true; } gPM<LO`;i <!-- DRAG DROP CODE --> gK"E4{y_@ if(NS) { -D30(g{
O window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN); km#Rh^ window.onmousedown = grabIt; 73d7'Fw window.onmousemove = moveIt; d+:pZ window.onmouseup = dropIt; } x*z$4)RP
if(IE) { .6nNqGua1 document.onmousedown = grabIt; N| L Ey document.onmousemove = moveIt; 9zK5Y+! document.onmouseup = dropIt; } d|(@#*{T] if(NS || IE) action = window.setInterval("heartBeat()",1); `(7HFq<N </script> |LNAd:0 //代码段四结束 \+B+M 7 </body> qdeS*rp\ </html>
|
|
[楼 主]
|
Posted: 2006-04-04 09:10 |
| |