DOM Event - Resize

Devtool Chrome Event Listener

About

The resize event occurs when the window is resized.

Example

  • The HTML with an explanation and two nodes that will be updated with the with and height respectively.
<p>Resize the browser window to fire the <mark>resize</mark> event.</p>
<p>Window width: <span id="width"></span></p>
<p>Window height: <span id="height"></span></p>
  • The Javascript that selects the width and height node and update them with the innerWidth and innerHeight value
const heightOutput = document.querySelector('#height');
const widthOutput = document.querySelector('#width');
heightOutput.textContent = parent.window.innerHeight;
widthOutput.textContent = parent.window.innerWidth;
  • The Javascript that updates dynamically the value with an event listener callback.
parent.window.addEventListener('resize', function() {
  heightOutput.textContent = parent.window.innerHeight;
  widthOutput.textContent = parent.window.innerWidth;
});
  • The output:





Discover More
Global Namespace Web Console Firefox
Browser - (Window | Tab) (Javascript Global scope)

window: is a javascript object that represents a tab in the whole browser that render a document. is the javascript global scope for the variable in the browser. is part of the web api holds the...
Devtool Chrome Event Listener
DOM - Event Type (name)

An event is categorize by its type which is a property of the event object The type of an event is also known as the name of the event (Ref)...
How to create a Debounce Function in Javascript?

A debounce is a function that: will wrap a callback function willnot let the callback function execute for each event will let the callback function execute only when a certain amount of time...



Share this page:
Follow us:
Task Runner