HTML 視窗 moveBy() 方法


HTML 視窗 moveBy() 方法使視窗相對於其當前座標移動。

語法

以下是語法 −

window.moveBy(x,y)

其中,x 和 y 分別定義了水平和垂直移動視窗的值(以畫素為單位)。

讓我們看一個 HTML 視窗 moveBy() 方法示例 −

示例

 直播演示

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      height: 100vh;
      background-color: #8BC6EC;
      background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%) no-repeat;
      text-align: center;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
   }
</style>
<body>
<h1>HTML Window moveBy() Method Demo</h1>
<button onclick="create()" class="btn">Create new window and then move it</button>
<script>
   function create(){
      var newWindow =window.open('','','width=150,height=150');
      newWindow.moveBy(550, 200);
   }
</script>
</body>
</html>

輸出

點選“建立新視窗並移動它”按鈕來生成一個新視窗,然後使用 moveBy() 方法移動它

更新於:01-Oct-2019

111 次瀏覽

啟動您的 職業

透過完成此課程獲得認證

開始
廣告
© . All rights reserved.