Will $(window).resize() trigger on orientation change? - JavaScript
Yes, the $(window).resize()
event will trigger on orientation change in JavaScript. This is because the orientation change of a device affects the size of the window, and the resize()
event is triggered whenever there is a change in the size of the window.
However, it is important to note that the resize()
event may not always be the most appropriate event to use when handling orientation changes. In some cases, it may be more appropriate to use the orientationchange
event, which is specifically designed to handle changes in device orientation.
To handle orientation changes using the orientationchange
event, you can use the following code:
$(window).on("orientationchange", function() {
// Handle orientation change here
});
By using the orientationchange
event instead of the resize()
event, you can ensure that your code is specifically designed to handle changes in device orientation, rather than just changes in window size.
Leave a Reply
Related posts