With the prevalence of using the CSS @media
query, we can now style web pages based on the resolution on which they are viewed. The width-dependent style / layout will occur immediately when you resize the browser window. In CSS, this is pretty straightforward e.g.
// The heart of "responsive design."
@media screen and (max-width: 1000px) { ... }
In the spirit of responsive design, can we adjust a JavaScript logic on-the-fly upon resolution changes? For example, if we have script that outputs a number '5' every 10 seconds, can we alter it to output '7' (at the same interval) when the browser window is resized to <300px?
// Default script
setTimeout(function() {
var i = 5;
console.log(i);
}, 10000);
// How to change the value of i to 7, upon window resize?
// Ideally, without a page reload.