// JavaScript Document var delta=1; //0.5 //缓冲 1为不缓冲 var collection; function floaters() { this.items = []; this.addItem = function(id,x,y,w,h,content) { document.write('
'+content+'
'); var newItem = {}; newItem.object = document.getElementById(id); newItem.x = x; newItem.y = y; this.items[this.items.length] = newItem; } this.play = function() { collection = this.items setInterval('play()',10); } } this.play=function play() { l=getscrollLeft(); t=getscrollTop(); if(screen.width<=0) { for(var i=0;i 0 ? 1 : -1) * Math.ceil(Math.abs(dx)); followObj.style.left = followObj.offsetLeft + dx + "px"; } if(followObj.offsetTop!=(t+followObj_y)) { var dy=(t+followObj_y-followObj.offsetTop)*delta; dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy)); followObj.style.top=followObj.offsetTop+dy+"px"; } } function getscrollTop()//得到当前显示内容的高 { if (document.documentElement.scrollTop>0) { if (document.documentElement.scrollTop>0) { return document.documentElement.scrollTop } }else { return document.body.scrollTop; } } function getscrollLeft()//得到当前显示内容的宽 { if (document.documentElement.scrollLeft>0) { if (document.documentElement.scrollLeft>0) { return document.documentElement.scrollLeft } }else { return document.body.scrollLeft; } } } /* ////////////////////////////// */ var fly_collection; var flyer; function flyers() { var clientW=document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth; var clientH=document.compatMode == "CSS1Compat" ? document.documentElement.clientHeight : document.body.clientHeight; this.items=[]; this.addItem=function(id,height,width,step,delay,content) { document.write('
' + content + '
'); var newItem={}; newItem.object=document.getElementById(id); newItem.x=parseInt(Math.random()*(clientW-width)+1); newItem.y=parseInt(Math.random()*(clientH-height)+1); newItem.step=step; newItem.delay=delay; newItem.height=height; newItem.width=width; newItem.xSign=newItem.x%2==1?1:-1; newItem.ySign=newItem.y%2==1?1:-1; this.items[this.items.length]=newItem; fly_collection=this.items; newItem.object.style.top=newItem.y+"px"; newItem.object.style.left=newItem.x+"px"; } this.play=function() { fly_collection=this.items; flyer=setInterval('playing()',30); } } function playing(id) { clientW=document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth; clientH=document.compatMode == "CSS1Compat" ? document.documentElement.clientHeight : document.body.clientHeight; scrollT= document.documentElement.scrollTop > 0 ? document.documentElement.scrollTop : document.body.scrollTop; scrollL= document.documentElement.scrollLeft > 0 ? document.documentElement.scrollLeft : document.body.scrollLeft; var isStop=false; if(arguments.length==1) { isStop=true; } for(i in fly_collection) { if(fly_collection[i].y+fly_collection[i].height>=clientH) { fly_collection[i].ySign=-1; } if(parseInt(fly_collection[i].x)+fly_collection[i].width>=clientW) { fly_collection[i].xSign=-1; } if(parseInt(fly_collection[i].y)<=0) { fly_collection[i].ySign=1; } if(parseInt(fly_collection[i].x)<=0) { fly_collection[i].xSign=1; } if (!isStop) { fly_collection[i].y=fly_collection[i].y+fly_collection[i].ySign*fly_collection[i].step; fly_collection[i].object.style.top=fly_collection[i].y+scrollT+"px"; fly_collection[i].x=fly_collection[i].x+fly_collection[i].xSign*fly_collection[i].step; fly_collection[i].object.style.left=fly_collection[i].x+scrollL+"px"; } } } function disable(ob){ ob.parentNode.parentNode.removeChild(ob.parentNode); } //下面注释的为飘动代码 /////////// var theFlyer = new flyers(); ///////////theFlyer.addItem('Fly1', 125, 100, 1, 10, '
关闭
'); /////////// theFlyer.play(); var theFlyer = new flyers(); theFlyer.addItem('Fly1', 200, 200, 1, 10, ''); theFlyer.play();