按下开始键以后
两个球一个按sinx从左向右移动,一个按cosx从右向左移动
到边界的时候不用反弹回来(比如sin球消失在右边,又从左边出来)
按停止键的时候不用reset(再次按开始的时候从原地方继续移动)求助高手帮忙啊

解决方案 »

  1.   

    先将图片上传到CSDN相册再发上来
      

  2.   

    写了个,不过不大适合,先看看吧.<script src="jquery.js"></script>
      <style>
    #box{border:1px solid #ccc;background:#eee;width:500px;height:400px; overflow:hidden;position:relative;z-index:1}
    #qiu1{width:30px;height:30px;background:url(q.png);position:absolute;z-index:2;left:50px;top:80px}
    #qiu2{width:30px;height:30px;background:url(q2.png);position:absolute;z-index:3;left:350px;top:300px}
      </style>
      <script>
    function move()
    {
    var q1=$("#qiu1")
    var q2=$("#qiu2")
    var x = q1.offset().left;
    var y = q1.offset().top;
    x++;
    var temp = Math.round(Math.sin(x)*100)
    y = 80+temp
    q1.css("left",x);
    q1.css("top",y);
    var p = $("#x")
    p.html("x:"+x+" y:"+y+"temp:"+temp)
    t = setTimeout("move()",100)
    }
    function stop()
    {
    clearTimeout(t)
    }
      </script>
     </head> <body>
    <div id="box">
    <div id="qiu1"></div>
    <div id="qiu2"></div>
    </div>
    <input type="button" value="start" onclick="move()"><input type="button" value="stop" onclick="stop()">
    <div id="x"></div>
     </body>
      

  3.   


    <body>
    <img id=red src=‘http://hi.csdn.net/attachment/201011/17/4557677_1289966797z070.gif’style='position:absolute;'>
    <img id=green src='http://hi.csdn.net/attachment/201011/17/4557677_1289966796RWR1.gif' style='position:absolute;'>
    <script type="text/javascript"> 
    var x=document.body.clientWidth;
    var y=document.body.clientHeight;
    var i=0;
    var go=1;
    function sh(){
      if (go){
        i++;
        if (i>x) i=0;
        j=Math.sin(Math.PI*i/x)*(1+y/2);
        red.style.top=j;
        red.style.left=i;
        j=Math.cos(Math.PI*i/x)*(1+y/2);
        green.style.top=j;
        green.style.left=i;
      }
      setTimeout('sh()',50);
    }
    sh();
    </script>
    <button onclick="go=1;">Start</button>
    <button onclick="go=0;">Stop</button>
    </body> 如何让两球不相交?就是各走各的,上面动一个,下面动一个。
    而且固定在一个区域里面,也就是说,只能消失在左右边界不能消失在上下边界
    我用div好像没用啊,另外改sin cos的振幅频率效果也不好,求大家帮助啊!!!
      

  4.   

    用div+频率解决了相交问题
    现在就是求助下面的球从右向左,上面的球从左向右怎么表示??谢谢!