一个小方块,从左上角,滑到右下角,弹回来左上,这个js如何写

解决方案 »

  1.   

    没有明白楼主的具体含义,动态的移动?是指TWEEN函数的效果么?
      

  2.   

    这个用HTML中的marquee标签即可完成,具体用法网上有很多;
    如果只想用JS来实现,参见这个资源:http://download.csdn.net/source/1112445
      

  3.   

    <script>
    var o, t, b;
    b = true;function initFly()
    {
    o = document.createElement("div");
    o.style.position = "absolute";
    o.style.width = 50;
    o.style.height = 50;
    o.style.left = 0;
    o.style.top = 0;
    o.style.background = "blue";
    document.body.appendChild(o);
    }function startFly()
    {
    t = setInterval("Fly()", 50)
    }function stopFly()
    {
    clearInterval(t);
    }function Fly()
    {
    var iLeft = parseInt(o.style.left);
    var iTop = parseInt(o.style.top);

    if(b)
    {
    if((iLeft <= document.body.clientWidth - 50) && (iTop <= document.body.clientHeight - 50)) 
    {
    o.style.left = iLeft + 5;
    o.style.top = iTop + 3;
    }
    else
    b = false;
    }
    else
    if((iLeft >= 0) && (iTop >= 0))
    {
    o.style.left = iLeft - 5;
    o.style.top = iTop - 3;
    }
    else
    b = true
    }
    </script><body onload="initFly()">
    <br /><br /><br />
    <input type="button" value="start" onclick="startFly()"><input type="button" value="stop" onclick="stopFly()">
      

  4.   

    发现csdn上各种马甲啊
    资源分闹的吧...
    我也是很多个马甲...