您好,欢迎来到源码搜藏!分享精神,快乐你我!提示:担心找不到本站?在百度搜索“源码搜藏”,网址永远不丢失!
  • 首 页
  • 在线工具
  • 当前位置:首页 > 网页特效 > 滚动代码 >

    代码精简的漂浮广告代码

    时间:2014-06-06 08:32 来源:互联网 作者:源码搜藏 浏览:收藏 挑错 推荐 打印

    运行代码保存代码复制代码 提示:您可以先修改部分代码再运行,保存代码功能在Firefox下无效。
    • 相对于其它的漂浮广告代码,这款代码比较简洁,调用方便,效果也不错,修改方便,可同时漂浮多个广告,互不干扰。
    • <SCRIPT LANGUAGE="JavaScript">
      GoGoGo("webjx1");
      GoGoGo("webjx3"); 
      GoGoGo("webjx2");
      function GoGoGo(objName)
      {
      var img=document.getElementById(objName) ;
      img.style.position="absolute";
      img.style.left=parseInt(window.screen.availWidth*Math.random()) + "px";
      img.style.top=parseInt(window.screen.availHeight*Math.random()) + "px";
      img.setAttribute("xDir",1);
      img.setAttribute("yDir",1);
      window.setInterval("randPosition(" + objName + ")","10","JavaScript");
      }
       
      function randPosition(obj)
      {
      var x=parseInt(obj.style.left);
      if(x>=window.screen.availWidth-obj.width-20)
      obj.setAttribute("xDir",-1);
      if(x<=0)
      obj.setAttribute("xDir",1);
      x+=parseInt(obj.getAttribute("xDir"));
      var y=parseInt(obj.style.top);
      if(y>=window.screen.availHeight-obj.height-100)
      obj.setAttribute("yDir",-1);
      if(y<=0)
      obj.setAttribute("yDir",1);
      y+=parseInt(obj.getAttribute("yDir"));
      obj.style.left=x +"px";
      obj.style.top =y +"px";
      }
      </SCRIPT>
    代码精简的漂浮广告代码由源码搜藏网整理,转载请注明出处http://www.codesocang.com/texiao/gundong/8410.html
    标签:网站源码