HTML 視窗 resizeBy() 方法
HTML 視窗 resizeBy() 方法透過指定的值相對於其當前大小調整視窗大小。
語法
以下是語法 −
window.resizeBy(w,h)
此處,w 和 h 分別定義調整視窗寬度和高度(以畫素為單位)的值。
讓我們看一個 HTML 視窗 resizeBy() 方法的示例 −
示例
<!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>輸出

單擊“建立新視窗”按鈕生成新視窗

現在單擊“調整視窗大小”按鈕調整新建立的視窗的大小 −

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP