HTML 的 onresize 事件屬性


當用戶調整瀏覽器視窗大小時,將觸發 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 事件屬性如何工作。

更新於:2019 年 9 月 26 日

90 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告