HTML Window resizeTo() 方法
htmlweb developmentfront end technology更新于 2024/1/15 6:04:17
HTML Window resizeTo() 方法根据指定值调整窗口相对于其当前大小的大小。
语法
以下是语法 −
window.resizeTo(w,h)
其中 w 和 h 分别定义了调整窗口宽度和高度的值(以像素为单位)。
让我们看一个 HTML Window resizeTo() 方法的示例 −
示例
<!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 resizeTo() 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.resizeTo(240, 240);
newWindow.focus();
}
</script>
</body>
</html>
输出

点击"创建新窗口"按钮即可生成新窗口:

现在点击"调整窗口大小"按钮即可调整新创建的窗口的大小 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

