<%@ Page Language="C#" AutoEventWireup="true" CodeFile="漂浮广告.aspx.cs" Inherits="漂浮广告" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <SCRIPT LANGUAGE="JavaScript">
<!--
        var x = 10;
        var y = 10;        function move() {
        document.getElementById('fly').style.pixelTop += y;
        document.getElementById('fly').style.pixelLeft += x;            var L = document.getElementById('fly').style.pixelLeft;
            var T = document.getElementById('fly').style.pixelTop;
            if (T < 0 || T > document.body.offsetHeight - document.getElementById('fly').offsetHeight) {
                y *= -1;
            }            if (L < 0 || L > document.body.offsetWidth - document.getElementById('fly').offsetWidth) {
                x *= -1;
            }
            setTimeout('move()', 100);
        }

//-->
</SCRIPT>
</head>
<body onload = 'move()'>
    <form id="form1" runat="server">
   <DIV id="fly" style="position:absolute">
<A href= target="_blank">
<IMG src="images/fish.gif" border="0">
</A></DIV>    </form>
</body>
</html>

解决方案 »

  1.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="漂浮广告.aspx.cs" Inherits="漂浮广告" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
       <title></title>
       <SCRIPT LANGUAGE="JavaScript">
    <!--
    var bodyfrm = ( document.compatMode.toLowerCase()=="css1compat" ) ? document.documentElement : document.body;
    var x = 10;
    var y = 10;
       
    var xx = 0;
    var yy = 0;

    var picWidth = 30; //设置图片宽度
    var picHeight = 30; //设置图片高度 alert(bodyfrm.clientWidth+","+bodyfrm.clientHeight)
    function move()
    {
        if(xx == 0)
        {
        document.getElementById('fly').style.pixelLeft += x;
        }
        else
        {
        document.getElementById('fly').style.pixelLeft -= x;
        }
       
        if(yy == 0)
        {
        document.getElementById('fly').style.pixelTop += y;
        }
        else
        {
        document.getElementById('fly').style.pixelTop -= y;
        }
       
        var L = document.getElementById('fly').style.pixelLeft;
        var T = document.getElementById('fly').style.pixelTop; if (T <= 0)
    {
    document.getElementById('fly').style.pixelTop = 15;
    yy = 0;
    }
    else if(T >= bodyfrm.clientHeight - picHeight)
    {
    document.getElementById('fly').style.pixelTop = bodyfrm.clientHeight - 10 - picHeight;
    yy = 1;
    } if (L <= 0)
    {
    document.getElementById('fly').style.pixelLeft = 15;
    xx = 0;
    }
    else if (L >= bodyfrm.clientWidth - picWidth)
    {
    document.getElementById('fly').style.pixelLeft = bodyfrm.clientWidth - 10 - picWidth;
    xx = 1;
    }
        setTimeout('move()', 100);
    }
    //-->
    </SCRIPT>
    </head>
    <body onload = 'move()'>
       <form id="form1" runat="server">
       <DIV id="fly" style="position:absolute">
    <A href= target="_blank">
    <IMG src="images/fish.gif" border="0">
    </A></DIV>   </form>
    </body>
    </html>