![Toca life world music](https://cdn3.cdnme.se/5447227/9-3/screenshot_6_64e62947e087c31b3e7101ab.jpg)
The width and height of the window will be shown on the page, and it will change as the size of the window is changed. After the start() function, we added the resize event, which will call the start() function when a user resizes the window. In the script tag, we have a function start(), which is used to change the text of the two spans with the width and height of the window.
![javascript window resize javascript window resize](https://i.stack.imgur.com/PhSIq.png)
The id of the span will be used to get the element in JavaScript. We added a br tag to move the cursor to a new line, and on the new line, we added another span with text Height=, and after that, we added another empty span with an id SpanID2. In the above code, we added a span with text Width=, and after that, we added an empty span with an id SpanID1 in the body section. In case you want to mimic the same behaviour in vanilla Javascript, here's the equivalent: var resizeId I'm personally making use of this trick on my fullPage.js library because it does a few changes on the DOM on resize.
![javascript window resize javascript window resize](https://i.stack.imgur.com/Xq6RD.png)
This counter of 500 milliseconds gets restarted with every change in the window dimensions (as we clear the timeout) so the function will only be called if the user stops resizing the window OR if the user resizes the window VERY slowly, which is very unlikely :)
![javascript window resize javascript window resize](https://i.stack.imgur.com/hlOv3.jpg)
ResizeId = setTimeout (doneResizing, 500 ) īasically what we do in this case is adding a timeout of 500 milliseconds to call our function doneResizing. For those cases we don't usually want to execute them tens of times while the user is still re-sizing the window to reach the desired size.įor these particular cases we can use a very simple trick: var resizeId Sometimes we need to execute functions which might take a while to execute or which might consume quite a few resources from the machine.
![javascript window resize javascript window resize](https://i.stack.imgur.com/J4B1H.png)
JQuery resize event (or Javascript one) is fired when the size of the browser's window (viewport) changes as pointed out in jQuery documentation.
![Toca life world music](https://cdn3.cdnme.se/5447227/9-3/screenshot_6_64e62947e087c31b3e7101ab.jpg)