阅读(3501) (0)

window属性:onresize

2018-05-25 13:44:10 更新

onresize属性

该onresize属性包含收到resize事件时触发的EventHandler。

onresize属性语法

window.onresize = funcRef;

参数

  • funcRef是对一个函数的引用。

onresize属性示例

window.onresize = doFunc;
<html>
<head>

<title>onresize test</title>

</head>

<body>
<p>Resize the browser window to fire the resize event.</p>

<p>Window height: <span id="height"></span></p>
<p>Window width: <span id="width"></span></p>

<script type="text/javascript">
  var heightOutput = document.querySelector('#height');
  var widthOutput = document.querySelector('#width');

  function resize() { 
    heightOutput.textContent = window.innerHeight;
    widthOutput.textContent = window.innerWidth;
  }

  window.onresize = resize;
</script>
</body>
</html>

笔记

调整窗口大小后触发resize事件。

规范

规范 状态 注释
HTML Living Standard 
在该规范中定义'onresize'。
Living Standard