Using the window resize Event
As an alternative to using media queries to detect changes in app width or orientation, you can use JavaScript to detect these changes. The window resize
event is raised whenever the size or the orientation of your app changes.
For example, the JavaScript file in Listing 11.4 displays a DIV element named sidebar
whenever the width of the app is greater than 600 pixels or the app is in landscape orientation.
(function () { "use strict"; function resize() { var width = document.documentElement.offsetWidth; var isLandscape = window.innerWidth > window.innerHeight; if (isLandscape && width > 600) ...
Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.