2008年8月29日

向心力

代码效果:向心力。

代码如下:

<!--将以下代码加入HTML的<Body></Body>之间--> <br /><!-- 用<BODY onload=init()>替换原有的--> <br /> <br /><SCRIPT language=JavaScript1.2> <br />function makevisible(cur,which){if(which==0) <br />cur.filters.alpha.opacity=100 <br />else <br />cur.filters.alpha.opacity=80 <br />}</SCRIPT><SCRIPT language=JavaScript1.2> <br />function high(which2){theobject=which2 <br />highlighting=setInterval("highlightit(theobject)",10) <br />}function low(which2){clearInterval(highlighting) <br />which2.filters.alpha.opacity=40 <br />}function highlightit(cur2){if(cur2.filters.alpha.opacity<100) <br />cur2.filters.alpha.opacity+=10 <br />else if(window.highlighting) <br />clearInterval(highlighting) <br />}</SCRIPT> <br /> <br /> <br /><head> <br /><SCRIPT language=JavaScript> <br /><!-- hide script from old browsers <br />var vers = navigator.appVersion; <br />if (vers.indexOf("3.")!=-1 || vers.indexOf("2.")!=-1) <br />{ <br />alert("You must use Navigator 4.0 or Internet Explorer 4.0 to view Dynamic HTML"); <br />document.writeln("<H2>You must use Navigator 4.0 or Internet Explorer 4.0 to view Dynamic HTML</H2>"); <br />} <br />// --> <br /></SCRIPT> <br /><SCRIPT language=JavaScript type=text/javascript><!-- <br /> <br />window.onerror=null; <br /> <br />//declare global variables <br /> <br />var ShockMode = 0; <br /> <br />var oTg = "\<"; <br /> <br />var cTg = "\>"; <br /> <br />var coTg = cTg + oTg; <br /> <br />var sQu = "'"; <br /> <br /> <br /> <br />ns4 = (document.layers)? true:false; <br /> <br />ie4 = (document.all)? true:false; <br /> <br /> <br /> <br />function init() { <br /> <br />if (ns4||ie4) { <br /> <br /> <br /> <br />box[0].activate() <br /> <br />box[1].activate() <br /> <br />box[2].activate() <br /> <br /> <br /> <br />box[0].show() <br /> <br />box[1].show() <br /> <br />box[2].show() <br /> <br /> <br /> <br />document.onmousemove = mouseMove; <br /> <br />if (ns4) document.captureEvents(Event.MOUSEMOVE) <br /> <br /> <br /> <br />} <br /> <br />} <br /> <br /> <br /> <br />function mouseMove(e) { <br /> <br />if (ns4) {var x=e.pageX; var y=e.pageY} <br /> <br />if (ie4) {var x=event.x; var y=event.y+document.body.scrollTop} <br /> <br /> <br /> <br />// if (y<400) { // restrict area <br /> <br /> <br /> <br />var distx = cx-x <br /> <br />var disty = cy-y <br /> <br />box[0].moveTo(cx-box[0].factor*distx-box[0].w/2,cy-box[0].factor*disty-box[0].h/2) <br /> <br />box[1].moveTo(cx-box[1].factor*distx-box[1].w/2,cy-box[1].factor*disty-box[1].h/2) <br /> <br />box[2].moveTo(cx-box[2].factor*distx-box[2].w/2,cy-box[2].factor*disty-box[2].h/2) <br /> <br />if (box.visible == false) { <br /> <br />for (var i=0;i<box.length;i++) box[i].show() <br /> <br />box.visible = true <br /> <br />} <br /> <br /> <br /> <br />/* <br /> <br />} <br /> <br />else { <br /> <br />if (box.visible == true) { <br /> <br />for (var i=0;i<box.length;i++) box[i].hide() <br /> <br />box.visible = false <br /> <br />} <br /> <br />} <br /> <br />*/ <br /> <br /> <br /> <br />} <br /> <br /> <br /> <br />// Box Object <br /> <br />function Box(name,x,y,width,height,color,vis) { <br /> <br />this.name = name <br /> <br />this.w = width <br /> <br />this.h = height <br /> <br />this.activate = BoxActivate <br /> <br />this.moveTo = BoxMoveTo <br /> <br />this.show = BoxShow <br /> <br />this.hide = BoxHide <br /> <br /> <br /> <br />this.css = css(name+'Top',x,y,width,1,color,vis)+ <br /> <br />css(name+'Bottom',x,y+height-1,width,1,color,vis)+ <br /> <br />css(name+'Left',x,y,1,height,color,vis)+ <br /> <br />css(name+'Right',x+width-1,y,1,height,color,vis) <br /> <br /> <br /> <br />this.div = oTg + 'DIV ID="'+name+'Top"' + coTg + '/DIV' + cTg + '\n'+ <br /> <br />oTg + 'DIV ID="'+name+'Bottom"' + coTg + '/DIV' + cTg + '\n'+ <br /> <br />oTg + 'DIV ID="'+name+'Left"' + coTg + '/DIV' + cTg + '\n'+ <br /> <br />oTg + 'DIV ID="'+name+'Right"' + coTg + '/DIV>\n\n' <br /> <br />} <br /> <br />function BoxActivate() { <br /> <br />this.lyrL = new DynLayer(this.name+'Left') <br /> <br />this.lyrR = new DynLayer(this.name+'Right') <br /> <br />this.lyrT = new DynLayer(this.name+'Top') <br /> <br />this.lyrB = new DynLayer(this.name+'Bottom') <br /> <br />} <br /> <br />function BoxMoveTo(x,y) { <br /> <br />this.lyrL.moveTo(x,y) <br /> <br />this.lyrR.moveTo(x+this.w,y) <br /> <br />this.lyrT.moveTo(x,y) <br /> <br />this.lyrB.moveTo(x,y+this.h) <br /> <br />} <br /> <br />function BoxShow() { <br /> <br />this.lyrL.show() <br /> <br />this.lyrR.show() <br /> <br />this.lyrT.show() <br /> <br />this.lyrB.show() <br /> <br />} <br /> <br />function BoxHide() { <br /> <br />this.lyrL.hide() <br /> <br />this.lyrR.hide() <br /> <br />this.lyrT.hide() <br /> <br />this.lyrB.hide() <br /> <br />} <br /> <br /> <br /> <br />if (ns4||ie4) { <br /> <br /> <br /> <br />box = new Array() <br /> <br /> <br /> <br />box[0] = new Box('box0',170,170,60,60,'#A3C7ED','hidden') <br /> <br />box[1] = new Box('box1',180,180,40,40,'#009CFF','hidden') <br /> <br />box[2] = new Box('box2',190,190,20,20,'#254081','hidden') <br /> <br /> <br /> <br />box[0].factor = 60/60 <br /> <br />box[1].factor = 40/60 <br /> <br />box[2].factor = 20/60 <br /> <br /> <br /> <br />box.visible = false <br /> <br /> <br /> <br />var str = css('START')+ <br /> <br />box[0].css+ <br /> <br />box[1].css+ <br /> <br />box[2].css+ <br /> <br />css('END') <br /> <br />document.write(str) <br /> <br /> <br /> <br />} <br /> <br /> <br /> <br /> <br />function DynLayer(id,nestref,iframe) { <br /> <br />if (!iframe && !DynLayerTest(id,nestref)) return <br /> <br />if (ns4) { <br /> <br />this.css = (nestref)? eval("document."+nestref+".document."+id) : document.layers[id] <br /> <br />this.x = this.css.left <br /> <br />this.y = this.css.top <br /> <br />} <br /> <br />else if (ie4) { <br /> <br />this.css = (iframe)? parent.frames[iframe].document.all[id].style : document.all[id].style <br /> <br />this.x = this.css.pixelLeft <br /> <br />this.y = this.css.pixelTop <br /> <br />} <br /> <br />this.id = id <br /> <br />this.nestref = nestref <br /> <br />this.w = (ns4)? this.css.clip.width : this.css.pixelWidth <br /> <br />this.h = (ns4)? this.css.clip.height : this.css.pixelHeight <br /> <br />this.doc = (ns4)? this.css.document : document <br /> <br />if (ns4) this.event = this.css <br /> <br />if (ie4) this.event = (iframe)? parent.frames[iframe].document.all[id] : document.all[id] <br /> <br />this.obj = id + "DynLayer" <br /> <br />eval(this.obj + "=this") <br /> <br />this.moveTo = DynLayerMoveTo <br /> <br />this.moveBy = DynLayerMoveBy <br /> <br />this.show = DynLayerShow <br /> <br />this.hide = DynLayerHide <br /> <br />this.slideInit = DynLayerSlideInit <br /> <br />this.clipInit = DynLayerClipInit <br /> <br />this.write = DynLayerWrite <br /> <br />} <br /> <br />function DynLayerMoveTo(x,y) { <br /> <br />if (x!=null) { <br /> <br />this.x = x <br /> <br />this.css.left = this.x <br /> <br />} <br /> <br />if (y!=null) { <br /> <br />this.y = y <br /> <br />this.css.top = this.y <br /> <br />} <br /> <br />} <br /> <br />function DynLayerMoveBy(x,y) { <br /> <br />this.moveTo(this.x+x,this.y+y) <br /> <br />} <br /> <br />function DynLayerShow() { <br /> <br />this.css.visibility = (ns4)? "show" : "visible" <br /> <br />} <br /> <br />function DynLayerHide() { <br /> <br />this.css.visibility = (ns4)? "hide" : "hidden" <br /> <br />} <br /> <br />function DynLayerSlideInit() { <br /> <br />this.slideTo = DynLayerSlideTo <br /> <br />this.slideBy = DynLayerSlideBy <br /> <br />this.slideStart = DynLayerSlideStart <br /> <br />this.slide = DynLayerSlide <br /> <br />this.onSlide = new Function("") <br /> <br />this.onSlideEnd = new Function("") <br /> <br />} <br /> <br />function DynLayerSlideTo(endx,endy,inc,speed,fn) { <br /> <br />if (endx==null) endx = this.x <br /> <br />if (endy==null) endy = this.y <br /> <br />var distx = endx-this.x <br /> <br />var disty = endy-this.y <br /> <br />this.slideStart(endx,endy,distx,disty,inc,speed,fn) <br /> <br />} <br /> <br />function DynLayerSlideBy(distx,disty,inc,speed,fn) { <br /> <br />var endx = this.x + distx <br /> <br />var endy = this.y + disty <br /> <br />this.slideStart(endx,endy,distx,disty,inc,speed,fn) <br /> <br />} <br /> <br />function DynLayerSlideStart(endx,endy,distx,disty,inc,speed,fn) { <br /> <br />if (this.slideActive) return <br /> <br />if (!inc) inc = 10 <br /> <br />if (!speed) speed = 20 <br /> <br />var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/inc <br /> <br />if (num==0) return <br /> <br />var dx = distx/num <br /> <br />var dy = disty/num <br /> <br />if (!fn) fn = null <br /> <br />this.slideActive = true <br /> <br />this.slide(dx,dy,endx,endy,num,1,speed,fn) <br /> <br />} <br /> <br />function DynLayerSlide(dx,dy,endx,endy,num,i,speed,fn) { <br /> <br />if (!this.slideActive) return <br /> <br />if (i++ < num) { <br /> <br />this.moveBy(dx,dy) <br /> <br />this.onSlide() <br /> <br />if (this.slideActive) setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+num+","+i+","+speed+",\""+fn+"\")",speed) <br /> <br />else this.onSlideEnd() <br /> <br />} <br /> <br />else { <br /> <br />this.slideActive = false <br /> <br />this.moveTo(endx,endy) <br /> <br />eval(fn) <br /> <br />this.onSlideEnd() <br /> <br />} <br /> <br />} <br /> <br />function DynLayerClipInit(clipTop,clipRight,clipBottom,clipLeft) { <br /> <br />this.clipTo = DynLayerClipTo <br /> <br />this.clipBy = DynLayerClipBy <br /> <br />this.clipValues = DynLayerClipValues <br /> <br />if (ie4) { <br /> <br />if (arguments.length==4) this.clipTo(clipTop,clipRight,clipBottom,clipLeft) <br /> <br />else this.clipTo(0,this.w,this.h,0) <br /> <br />} <br /> <br />} <br /> <br />function DynLayerClipTo(t,r,b,l) { <br /> <br />if (t==null) t = this.clipValues('t') <br /> <br />if (r==null) r = this.clipValues('r') <br /> <br />if (b==null) b = this.clipValues('b') <br /> <br />if (l==null) l = this.clipValues('l') <br /> <br />if (ns4) { <br /> <br />this.css.clip.top = t <br /> <br />this.css.clip.right = r <br /> <br />this.css.clip.bottom = b <br /> <br />this.css.clip.left = l <br /> <br />} <br /> <br />else if (ie4) this.css.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)" <br /> <br />} <br /> <br />function DynLayerClipBy(t,r,b,l) { <br /> <br />this.clipTo(this.clipValues('t')+t,this.clipValues('r')+r,this.clipValues('b')+b,this.clipValues('l')+l) <br /> <br />} <br /> <br />function DynLayerClipValues(which) { <br /> <br />if (ie4) var clipv = this.css.clip.split("rect(")[1].split(")")[0].split("px") <br /> <br />if (which=="t") return (ns4)? this.css.clip.top : Number(clipv[0]) <br /> <br />if (which=="r") return (ns4)? this.css.clip.right : Number(clipv[1]) <br /> <br />if (which=="b") return (ns4)? this.css.clip.bottom : Number(clipv[2]) <br /> <br />if (which=="l") return (ns4)? this.css.clip.left : Number(clipv[3]) <br /> <br />} <br /> <br />function DynLayerWrite(html) { <br /> <br />if (ns4) { <br /> <br />this.doc.open() <br /> <br />this.doc.write(html) <br /> <br />this.doc.close() <br /> <br />} <br /> <br />else if (ie4) { <br /> <br />this.event.innerHTML = html <br /> <br />} <br /> <br />} <br /> <br />function DynLayerTest(id,nestref) { <br /> <br />if (!DynLayerTest.count) DynLayerTest.count = 0 <br /> <br />var ref = new Array() <br /> <br />if (nestref) ref = nestref.split('.document.') <br /> <br />ref[ref.length] = id <br /> <br />var refstr = (ns4)? 'document.'+ref[0] : 'document.all.'+ref[0] <br /> <br />for (var i=1; i<=ref.length; i++) { <br /> <br />if (eval(refstr)) { <br /> <br />if (ref.length==i) return true <br /> <br />else refstr += (ns4)? '.document.'+ref[i] : '.all.'+ref[i] <br /> <br />} <br /> <br />else { <br /> <br />var str ='DynLayer Error:' <br /> <br />for (j in ref) { <br /> <br />str += '\n'+ref[j] <br /> <br />if (j==i-1) str += ' <-- this layer cannot be found' <br /> <br />} <br /> <br />if (DynLayerTest.count++<5) alert(str) <br /> <br />return false <br /> <br />} <br /> <br />} <br /> <br />return false <br /> <br />} <br /> <br />function DynLayerInit(nestref) { <br /> <br />if (!DynLayerInit.refArray) { <br /> <br />DynLayerInit.refArray = new Array() <br /> <br />DynLayerInit.refArray.i = 0 <br /> <br />} <br /> <br />if (ns4) { <br /> <br />if (nestref) ref = eval('document.'+nestref+'.document') <br /> <br />else {nestref = ''; ref = document;} <br /> <br />for (var i=0; i<ref.layers.length; i++) { <br /> <br />var divname = ref.layers[i].name <br /> <br />var index = divname.indexOf("Div") <br /> <br />if (index > 0) { <br /> <br />eval(divname.substr(0,index)+' = new DynLayer("'+divname+'","'+nestref+'")') <br /> <br />} <br /> <br />if (ref.layers[i].document.layers.length > 0) { <br /> <br />DynLayerInit.refArray[DynLayerInit.refArray.length] = (nestref=='')? ref.layers[i].name : nestref+'.document.'+ref.layers[i].name <br /> <br />} <br /> <br />} <br /> <br />if (DynLayerInit.refArray.i < DynLayerInit.refArray.length) { <br /> <br />DynLayerInit(DynLayerInit.refArray[DynLayerInit.refArray.i++]) <br /> <br />} <br /> <br />} <br /> <br />else if (ie4) { <br /> <br />for (var i=0; i<document.all.tags("DIV").length; i++) { <br /> <br />var divname = document.all.tags("DIV")[i].id <br /> <br />var index = divname.indexOf("Div") <br /> <br />if (index > 0) { <br /> <br />eval(divname.substr(0,index)+' = new DynLayer("'+divname+'")') <br /> <br />} <br /> <br />} <br /> <br />} <br /> <br />return true <br /> <br />} <br /> <br />function css(id,left,top,width,height,color,vis,z) { <br /> <br />if (id=="START") return '\<STYLE TYPE="text/css"\>\n' <br /> <br />else if (id=="END") return '\</STYLE\>' <br /> <br />var str = (left!=null && top!=null)? '#'+id+' {position:absolute; left:'+left+'; top:'+top+'; ' : '#'+id+' {position:relative; ' <br /> <br />if (width!=null) str += 'width:'+width+'; ' <br /> <br />if (height!=null) str += 'height:'+height+'; clip:rect(0,'+width+','+height+',0); ' <br /> <br />if (color!=null) str += 'background-color:'+color+'; layer-background-color:'+color+'; ' <br /> <br />if (vis!=null) str += 'visibility: '+vis+'; ' <br /> <br />if (z!=null) str += 'z-index: '+z+'; ' <br /> <br />str += '}\n' <br /> <br />return str <br /> <br />} <br /> <br />// --></SCRIPT> <br /><BGSOUND src="" loop=infinite> <br /><META content="Microsoft FrontPage 4.0" name=GENERATOR> <br /><style fprolloverstyle>A:hover {color: #FF0000; text-decoration: underline} <br /></style> <br /></HEAD> <br /><SCRIPT language=JavaScript type=text/javascript><!-- <br /> <br />if (ns4||ie4) { <br /> <br />winW = (ns4)? window.innerWidth-16 : document.body.offsetWidth-20 <br /> <br />winH = (ns4)? window.innerHeight : document.body.offsetHeight <br /> <br />cx = winW/2 <br /> <br />cy = winH/2 <br /> <br />document.write(box[2].div) <br /> <br />document.write(box[1].div) <br /> <br />document.write(box[0].div) <br /> <br />} <br /> <br />//--></SCRIPT> <br />

1 条评论:

风释 说...

由于编辑器的问题,如果代码无法显示请连接

http://jiaoliudi.blog.hexun.com/cate.aspx?cateid=732507&cate=%bf%d5%bc%e4%bd%a8%c9%e8