I have this doubt, I have a menu in which I run a javascript code or another depending on whether its width is greater or less than its height, works me well the first time the screen resolution is detected, but if there is a change of resolution or a change of orientation does not detect it, and despite for example of having changed to portrait orientation still executing the landscape orientation code. Is there any way to solve this? regards
Asked
Active
Viewed 631 times
-1
-
Look into the [`resize`](https://developer.mozilla.org/en-US/docs/Web/Events/resize) event and the [`orientationchange`](https://developer.mozilla.org/en-US/docs/Web/Events/orientationchange) event. – Mike Cluck Oct 02 '17 at 15:36
-
Please share code. We cannot help you without code. – zero298 Oct 02 '17 at 15:36
-
Already solved, this is the end result: window.onresize = function(){ location.reload(); } – manuhverso Oct 02 '17 at 16:46
1 Answers
2
You could use an eventlistener and listen on the resize event.
window.addEventListener('resize', () => {
// function body
});
But I think this is rather a styling issue and you should consider to use a different approach.
mstruebing
- 1,482
- 1
- 13
- 28