Contents

matchMedium

Evaluates the given string as a media query and returns the result.

Declaration

boolean matchMedium(
    optional DOMString mediaquery
);

Parameters

  • mediaquery:

    The media query to evaluate.

Return Value

true if the media query is logically true; otherwise, false.

Discussion

For example, window.styleMedia.matchMedium("(color)") returns true if the display device is a color device. You can also use this method to check whether the browser supports 3D transforms as follows:

if ('styleMedia' in window && window.styleMedia.matchMedium("(-webkit-transform-3d)")) {
  // Insert 3D code here
}

Or check to see whether the browser supports animations as follows:

if ('styleMedia' in window && window.styleMedia.matchMedium("(-webkit-animation)")) {
  // Insert animation code here
}