jQuery window width matching CSS media query
When you want to get the exact same breakpoints in jQuery as you have in your CSS media queries, the script below does it. Using the window width like $(window).width() has a small difference in pixels due to the scrollbar which is annoyingly taken into account. Many other variations didn't work either for me. This one covers it all:
In your js file:
In your js file:
function viewport() { var e = window, a = 'inner'; if (!('innerWidth' in window)) { a = 'client'; e = document.documentElement || document.body; } return { width : e[a + 'Width'], height : e[a + 'Height'] }; } var windowWidth = viewport().width;
Comments
Add new comment