当前位置:首页 > 网页特效 > 滚动代码 >

代码精简的漂浮广告代码

时间: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>
由源码搜藏网整理,转载请注明出处https://www.codesocang.com/tx-gundong/8410.html

滚动代码下载排行

最新文章