Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

HTML Window resizeBy() Method


HTML Window resizeBy() วิธีการปรับขนาดหน้าต่างที่สัมพันธ์กับขนาดปัจจุบันด้วยค่าที่ระบุ

ไวยากรณ์

ต่อไปนี้เป็นไวยากรณ์ -

window.resizeBy(w,h)

ที่นี่ w และ h กำหนดค่าของการปรับขนาดความกว้างและความสูงของหน้าต่างเป็นพิกเซลตามลำดับ

ให้เราดูตัวอย่างของ HTML Window resizeBy() Method -

ตัวอย่าง

<!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: 20%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
   }
</style>
<body>
<h1>HTML Window resizeBy() Method Demo</h1>
<button onclick="create()" class="btn">Create a new window</button>
<button onclick='resize()' class="btn">Resize the window</button>
<script>
   var newWindow;
   function create(){
      newWindow =window.open('','','width=80,height=80');
   }
   function resize(){
      newWindow.resizeBy(100, 100);
      newWindow.focus();
   }
</script>
</body>
</html>

ผลลัพธ์

HTML Window resizeBy() Method

คลิกที่ “สร้างหน้าต่างใหม่ ” เพื่อสร้างหน้าต่างใหม่:

HTML Window resizeBy() Method

ตอนนี้คลิกที่ “ปรับขนาดหน้าต่าง ” เพื่อปรับขนาดหน้าต่างที่สร้างขึ้นใหม่ -

HTML Window resizeBy() Method