I've found that using the Modernizr.mq() function to check media queries is a much more accurate way to run Javascript based on the viewport width, because it matches up with my CSS.
However, is it possible to get a width value from Modernizr?
Using built-in tests, nope, that's not possible. At least, there are no mentions in the Modernizr docs.
However, you don't need Modernizr to get the dimensions of your browser. You can do it by using plain javascript:
var width = document.documentElement.clientWidth;
var height = document.documentElement.clientHeight;
Original answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With