HTML onresize 事件属性
htmlweb developmentfront end technology更新于 2025/12/15 22:36:17
当用户调整浏览器窗口大小时,HTML onresize 属性会被触发。
语法
以下是语法 −
<tagname onresize=”script”></tagname>
让我们看一个 HTML onresize 事件属性的示例 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
height: 100vh;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
padding: 20px;
}
</style>
</head>
<body onresize="resizeFn()">
<h1>HTML onresize Event Attribute Demo</h1>
<p>Now resize the browser window</p>
<script>
function resizeFn() {
document.body.style.background = 'linear-gradient(45deg, #8BC6EC 0%, #9599E2 100%) no-repeat';
}
</script>
</body>
</html>
输出

现在调整浏览器窗口的大小来观察 onresize 事件属性如何工作。

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

