当鼠标在图片上方时,图片停止漂浮,点击关闭按钮可隐藏图片。
varxPos=0;
varyPos=0;
vardirectionX=true;
vardirectionY=true;
varstep=1;
varspeed=1;
varfloat=document.getElementById("float");
functionmove(){
varheight=document.documentElement.clientHeight;
varwidth=document.documentElement.clientWidth;
varimgHeight=float.offsetHeight;
varimgWidth=float.offsetWidth;
float.style.left=xPos+document.documentElement.scrollLeft+"px";
float.style.top=yPos+document.documentElement.scrollTop+"px";
if(directionX){xPos=xPos+step;}else{xPos=xPos-step;}
if(xPos<=0){xPos=0;directionX=true;}
if(xPos>=width-imgWidth){xPos=width-imgWidth;directionX=false;}
if(directionY){yPos=yPos+step;}else{yPos=yPos-step;}
if(yPos<=0){yPos=0;directionY=true;}
if(yPos>=height-imgHeight){yPos=height-imgHeight;directionY=false;}
t=setTimeout(move,speed);
}
float.onmouseover=function(){clearTimeout(t);}
float.onmouseout=function(){t=setTimeout("move()",speed);}