[JavaScript] JavaScript实现的漂浮广告效果代码 →→→→→进入此内容的聊天室

来自 , 2021-03-16, 写在 JavaScript, 查看 133 次.
URL http://www.code666.cn/view/bea6cfd5
  1. <body>
  2. <div id="float" style=" position:absolute; z-index:3">
  3. <img id="img1" src="http://www.sharejs.com/images/logo.png" style=" border:1px #ccc solid" /><img id="img2" onClick="float.style.display='none'" src="关闭图片" style=" position:absolute; margin-left:-13px;" />
  4. </div>
  5. <script type="text/javascript">
  6. var xPos=0;
  7. var yPos=0;
  8. var directionX=true;
  9. var directionY=true;
  10. var step=1;
  11. var speed=1;
  12. var float=document.getElementById("float");
  13. function move(){
  14.         var height=document.documentElement.clientHeight;
  15.         var width=document.documentElement.clientWidth;
  16.         var imgHeight=float.offsetHeight;
  17.         var imgWidth=float.offsetWidth;
  18.         float.style.left=xPos+document.documentElement.scrollLeft+"px";
  19.         float.style.top=yPos+document.documentElement.scrollTop+"px";
  20.         if(directionX){xPos=xPos+step;}else{xPos=xPos-step;}
  21.         if(xPos<=0){xPos=0;directionX=true;}
  22.         if(xPos>=width-imgWidth){xPos=width-imgWidth;directionX=false;}
  23.        
  24.         if(directionY){yPos=yPos+step;}else{yPos=yPos-step;}
  25.         if(yPos<=0){yPos=0;directionY=true;}
  26.         if(yPos>=height-imgHeight){yPos=height-imgHeight;directionY=false;}
  27.         t=setTimeout(move,speed);
  28.         }
  29.         float.onmouseover=function(){clearTimeout(t);}
  30.         float.onmouseout=function(){t=setTimeout("move()",speed);}
  31. window.onload=move();
  32. </script>
  33. </body>
  34. //javascript/8893

回复 "JavaScript实现的漂浮广告效果代码"

这儿你可以回复上面这条便签

captcha