阿七
级别: 未验证会员
精华:
0
发帖: 909
威望: 0 点
金钱: 2161 RMB
贡献值: 0 点
在线时间:512(小时)
注册时间:2006-03-29
最后登录:2008-08-07
|
网页中多层效果的灵活使用
动态的网页技术(DHTM)已经非常普及,本文强力向大家推荐一段完整并且是经典的网页多层代码,适用于IE及NETSCAPE游览器,可实现完善的二层网页功能,具体代码请见面文后程序。
SM#]H-3
gCS<iBT(7 该段代码功能:打开该网页文件之后,将在正常的网页之上,浮动另外一层网页内容,可用鼠标随意移动第二层网页在第一层上的位置,并且当屏幕滚动时,第二图层可始终保持同第一图层的相对位置,效果非常好。 2;`1h[,-^ $9#H04.x 适用场合:有了这段代码,你可以对很多原有的网页进行改造,使游览者更为方便,比如可用于留言簿,第一层放置留言内容,浮动的第二层放置留言表单,这样游览留言操作和观察留言内容可在同一页面完成,并且无论屏幕滚动到什么位置,留言表单始终出现在屏幕之上,这无疑是最方便的留言系统工作方式。再比如可做为一般网页的导航条,有很多人为了编制美观的页面而放弃使用分栏导航页面方式,而使用整个页面,这样的页面每进入到一个分栏目,都要重新调入整个页面。有了这项技术,可以在原完整的页面之上,浮动一层导航菜单,即方便了导航又保持了页面的完整。另外也可以在某些页面之上浮动一个特定的图像或其它页面内容,等等,总之,这种技术应用非常广泛。 7kLz[N6Ll jD]~ AwRJ 代码说明:代码段一可放置在网页的文件头处,即段。代码段二为正常的网页内容,即第一层的代码内容。第三段为第二层网页的代码段,即浮动的网页内容。代码段四为必要的控制代码,可放置在网页的最后处。灵活使用:下面的代码是完整的网页文件代码,把代码段二和代码段三换成你自己所需要的内容就可以了,但由于本网页文件涉及两个网页的制作过程,可能制作起来相当费力,并且很多网页制作工具不支持这一功能,用低级的网页工具存盘后将失去浮动效果,所以对于这样的网页最好的维护方法是分页维护,即分别编制两个完整的网页内容,之后按要求合并在一个网页文件内即可。这样向你介绍一种最可取的方法,众所周知,现在的网页技术可以实现在一个网页内调用其它网页的功能,即所谓的画中画功能,所以完全可以把代码二和代码三换成固定的调用其它网页的固定代码,之后只需要对这两个单独的页维护就可以了。具体可用下面的代码替换代码二和三: ^ogt+6c jXx<`I+] ILAYER id="ad1" visibility="hidden" height="60"> UgNu`$m+ </ILAYER> ~"H,/m%2o <NOLAYER> BLdvyVFx <IFRAME SRC="h1.htm" width="100%" height="60" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"> BwGfTua </IFRAME> 其中SRC:用于指定打开的网页地址; Wx}8T[A} width:该表格占用的宽度; DB|Y height:该表格点用的高度; 3?9IJ5p marginwidth:网页内容在表格右侧的预留宽度; t;Sb/ 3 marginheight:网页内容在表格顶部预留的高度; ^WgX Qtn hspace:网页右上角的横坐标; A*2jENgci vspace:网页右上角的纵坐标; I\{
1u frameborder:是否显示边缘; n8
i] z scrolling:是否出现滚动条; pfD c9PMj 具体使用时把h1.htm分别换成不同的网页文件名。 L:j<c5 完成的网页文件代码如下: R6 .hA_ih <html> @/.;Xw] <head> @[<><uTH <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> ]"hFC<w //代码段一 q
4:o#K# <style type="text/css"><!-- QUc= &5 % #floater {position: absolute;left: 500;top: 146;width: 125;visibility: visible;z-index: 10;} /wEhVR`= --> D9=KXo^ </style> HZC"nb}r4 //代码段一结束 w!-gJmX> <title>浮动层</title> qFCOUl </head> ?}tFN_X" //代码段二(第一层内容,目前为空) EReZkvseC <body bgcolor="#FFFFFF"> _LEK
% <BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR> I(L,8n5 //代码段二结束 |P
HT694Uz //代码段三(浮动层内容,目前为一简单表格) 7hD>As7`/ <div ID="floater" style="left: 0px; top: 1px"> X8a/ `Y, <table border="1" cellpadding="0" cellspacing="0" 6
6EV$*dRL bgcolor="#25A78D" bordercolordark="#00FFFF" *e TqVG. bordercolorlight="#000000"> y
*jp79G <tr> vAF
"n <td>111<a href="file:///G:/C/NEW/dhtml2.htm">1111</a></td> ;40/yl3r3[ <td>2222222</td> >reU#j </tr> Olt?~} </table> ~tS Z%q </div> In"ZIKaC //代码段三结束 j|DsG, //代码段四 r4b 6 c <script LANGUAGE="JavaScript"> 93)sk/j self.onError=null; ~OYiq}g currentX = currentY = 0; t:x\kp whichIt = null; 9IdA%RM~mH lastScrollX = 0; lastScrollY = 0; +6M}O[LP NS = (document.layers) ? 1 : 0; Z!a=dnwHz IE = (document.all) ? 1: 0; $D~0~gn~ <!-- STALKER CODE --> 1Z/(G1 function heartBeat() { e
}?db if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; } <Uk}o8E if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; } \"w"$9o6 if(diffY != lastScrollY) { kUL'1!j7 percent = .1 * (diffY - lastScrollY); WH#1zv if(percent > 0) percent = Math.ceil(percent); A_"w^E{P else percent = Math.floor(percent); m^!Z_]A![ if(IE) document.all.floater.style.pixelTop += percent; p;`>e>$ if(NS) document.floater.top += percent; 6IN
e@ lastScrollY = lastScrollY + percent; } x xHY+(m if(diffX != lastScrollX) { D=A&+6B@- percent = .1 * (diffX - lastScrollX); ;Zcswt8]u if(percent > 0) percent = Math.ceil(percent); nI?[rCM else percent = Math.floor(percent); { T/[cu< if(IE) document.all.floater.style.pixelLeft += percent; nmee 'oEw if(NS) document.floater.left += percent; "@^k)d$ lastScrollX = lastScrollX + percent;}} Q^P}\wb> <!-- /STALKER CODE --> ^ox=H
NV <!-- DRAG DROP CODE --> aL\PGdgO function checkFocus(x,y) { LRxZcxmy stalkerx = document.floater.pageX; #H&|*lr
stalkery = document.floater.pageY; A7{\</Z stalkerwidth = document.floater.clip.width; O0x,lq stalkerheight = document.floater.clip.height; L]|gZ&^ if( (x > stalkerx && x < (stalkerx+stalkerwidth)) && (y > stalkery && y < (stalkery+stalkerheight))) return true; DaQ?\uq else return false; } nQZx=JK function grabIt(e) { n-2]M05O if(IE) {whichIt = event.srcElement; a@K%06A;' while (whichIt.id.indexOf("floater") == -1) { ;J( 8
L whichIt = whichIt.parentElement; e-/&$Qq if (whichIt == null) { return true; } } R{`(c/%8 whichIt.style.pixelLeft = whichIt.offsetLeft; GRIti9GD whichIt.style.pixelTop = whichIt.offsetTop; <Xhm`rH currentX = (event.clientX + document.body.scrollLeft); |)th1
UH currentY = (event.clientY + document.body.scrollTop); } else { F@7jx:tI window.captureEvents(Event.MOUSEMOVE); B N5[,J if(checkFocus (e.pageX,e.pageY)) { m,_Z6=I: whichIt = document.floater; .[KrlfI StalkerTouchedX = e.pageX-document.floater.pageX; e`_
LEv StalkerTouchedY = e.pageY-document.floater.pageY; } } #
pow ub return true;} B2vh-%63 function moveIt(e) { ,Ks8*;#r if (whichIt == null) { return false; } c9
eM/*: if(IE) { x_Y!5yg
E newX = (event.clientX + document.body.scrollLeft); ;%9 |kU newY = (event.clientY + document.body.scrollTop); !;v|' I distanceX = (newX - currentX); distanceY = (newY - currentY); X=&ET)8-Y currentX = newX; currentY = newY; ^98~U\ar whichIt.style.pixelLeft += distanceX; <oV(7 whichIt.style.pixelTop += distanceY; DU'`ewLL7 if(whichIt.style.pixelTop < document.body.scrollTop) whichIt.style.pixelTop = document.body.scrollTop; (NU
NHxi5B if(whichIt.style.pixelLeft < document.body.scrollLeft) whichIt.style.pixelLeft = document.body.scrollLeft; ]
y'>=a|T if(whichIt.style.pixelLeft > document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20) whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20; #&aqKVY 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; n5NsmVW \x event.returnValue = false; %/.b~|,- } else { 8qT
ys8 whichIt.moveTo(e.pageX-StalkerTouchedX,e.pageY-StalkerTouchedY); \V8PhO;j if(whichIt.left < 0+self.pageXOffset) whichIt.left = 0+self.pageXOffset; HyZqUbHa if(whichIt.top < 0+self.pageYOffset) whichIt.top = 0+self.pageYOffset; q"J]%zO if( (whichIt.left + whichIt.clip.width) >= (window.innerWidth+ self.pageXOffset-17)) whichIt.left = ((window.innerWidth+self.pageXOffset)-whichIt.clip.width)-17; $a"O
c if( (whichIt.top + whichIt.clip.height) >= (window.innerHeight+ self.pageYOffset-17)) whichIt.top = ((window.innerHeight+self.pageYOffset)-whichIt.clip.height)-17; 0R'?~`aTt return false; } return false; } JIOR4' 9 function dropIt() { ]Ie 0S~ whichIt = null; b9HtR -iR; if(NS) window.releaseEvents (Event.MOUSEMOVE); [!#L6&:a8 return true; } Fj3a.' <!-- DRAG DROP CODE --> | rtD.,m if(NS) { XJ|
<? window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN); L+i=VGm0 window.onmousedown = grabIt; +.FEq*V window.onmousemove = moveIt; ,j_i?Ff window.onmouseup = dropIt; } c]o'xd,T8\ if(IE) { "e>;'%W document.onmousedown = grabIt; `e&Suyf4B document.onmousemove = moveIt; |3"KK document.onmouseup = dropIt; } )}Kf= if(NS || IE) action = window.setInterval("heartBeat()",1); A]oV"`f </script> 7.j?U //代码段四结束 2eY_%Y0 </body> ~HsJUro </html>
|
|
[楼 主]
|
Posted: 2006-04-04 09:10 |
| |