GlobalEventHandlers.onresize

La propriété onresize,rattachée au mixin GlobalEventHandlers, est un gestionnaire d'évènements (en-US) qui permet de traiter les évènements resize.

Un évènement resize est déclenché après que la fenêtre a été redimensionnée.

Syntaxe

js

window.onresize = refFonction;

Value

refFonction est un nom de fonction ou une expression de fonction. La fonction reçoit un objet FocusEvent comme unique argument.

Exemple

Journaliser l'évolution de la taille de la fenêtre

HTML

html

<p>Redimensionnez la fenêtre pour déclencher l'évènement <code>resize</code>.</p>
<p>Hauteur de la fenêtre : <span id="height"></span></p>
<p>Largeur de la fenêtre : <span id="width"></span></p>

JavaScript

js

const heightOutput = document.querySelector('#height');
const widthOutput = document.querySelector('#width');

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

window.onresize = resize;

Résultat

Spécifications

No specification found

No specification data found for api.GlobalEventHandlers.onresize.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Compatibilité des navigateurs

BCD tables only load in the browser

Voir aussi