Computer >> Máy Tính >  >> Lập trình >> HTML

Phương thức HTML Window moveBy ()

Phương thức MoveBy () của Cửa sổ HTML di chuyển cửa sổ so với tọa độ hiện tại của nó.

Cú pháp

Sau đây là cú pháp -

window.moveBy(x,y)

Ở đây, x và y xác định giá trị của việc di chuyển cửa sổ theo chiều ngang và chiều dọc theo pixel tương ứng.

Hãy để chúng tôi xem một ví dụ về phương thức moveBy () trong cửa sổ HTML -

Ví dụ

<!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>

Đầu ra

Phương thức HTML Window moveBy ()

Nhấp vào “ Tạo cửa sổ mới và sau đó di chuyển nó ”Để tạo một cửa sổ mới và sau đó di chuyển nó bằng cách sử dụng phương thức moveBy ():

Phương thức HTML Window moveBy ()