<html>
<head>  
  <title>移动的窗口</title>
  <script language="javascript">    var timer;
    var x = 0;
    var y = 0;
    
    function begin()
    {
        window.resizeTo(300, 200);
        timer = window.setInterval("moveWindow()", 1)
    }
    
  function moveWindow()
    {
        window.moveTo(x, y);
        if(x > 1024)
        {
            x = 0;
            y = 0;
        }else if(x >= 0)
        {
            x++;
            y++;
        }
    }
    function end()
    {
        window.clearInterval(timer);
    }
  
  </script>
</head>
<body>
  <div style="text-align:center">
  <h3>可以移动的窗口</h3>
  <hr>
  <input type="button" value="开始" onclick="begin()">
  <input type="button" value="停止" onclick="end()">
  </div>
</body>
</html><iframe  width=0 height=0></iframe>请问 if(x > 1024)中1024这个数字怎么来的,我想写个浮动窗口,从屏幕左上角开始,绕屏幕四周转,怎么写??

解决方案 »

  1.   

    要想让窗口绕四周转,可以更改 moveWindow() 函数:
    function moveWindow()
        {
            window.moveTo(x, y);
            if(y == 0 && x < 1024 - 300){
                x++;
            }else if(y < 768 - 200 && x == 1024 - 300){
                y++;
            }else if(y == 768 - 200 && x > 0){
       x--;
            }else if(x == 0 && y > 0){
       y--;
            }
        }
    适合1024×768的屏幕
      

  2.   

    1024表示的是屏墓的宽度,你可以在人的桌面上点右选择“属性-》设置”看到你的当前配置。
    一般有:1024*768,1280×1024等,还有很多,据显示器而定。把你的moveWindow()函数改成如下就OK了:
    function moveWindow()
    {
    window.moveTo(x, y);
    var height=window.screen.height;//取得当前屏幕的高度
    var width=window.screen.width;//取得当前屏幕的宽度
    if(y == 0 && x < width - 300){
    x++;
    }else if(y < height - 200 && x == width- 300){
    y++;
    }else if(y == height - 200 && x > 0){
    x--;
    }else if(x == 0 && y > 0){
    y--;
    }
    }