GlobalEventHandlers.onresize
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
La propriété onresize
,rattachée au mixin GlobalEventHandlers
, est un gestionnaire d'évènements 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
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
<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
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
must be provided
Spécifications
Specification |
---|
CSSOM View Module # eventdef-window-resize |
Compatibilité des navigateurs
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
resize event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
Voir aussi
- L'évènement
resize