I want to create a dynamic variable that updates automatically as the browser window is resized in pixels. I need this variable to change without needing the page to refresh, and I don't want it written in the HTML document as it's used further down in the script.
Here's what I have so far:
window.onload = function() {
var windowwidth = window.innerWidth;
};
window.onresize = function() {
var windowwidth = window.innerWidth;
};
console.log(windowwidth);
SOLUTION BELOW
window.onload = function() {
currentWidth(document.body.clientWidth);
};
window.onresize = function() {
currentWidth(document.body.clientWidth);
};
function currentWidth(w) {
// Math using w goes here
}