匹配 只读特性在 MediaQueryList 接口是 布尔 that returns true document currently matches the media query list, or false 若不。

You can be notified when the value of 匹配 changes by watching for the change event to be fired at the MediaQueryList .

句法

var matches = <varm>MediaQueryList.matches;
					

A 布尔 which is true document currently matches the media query list; otherwise, it's false .

范例

This example detects viewport orientation changes by creating a media query using the orientation media feature:

function addMQListener(mq, callback) {
  if (mq.addEventListener) {
    mq.addEventListener("change", callback);
  } else {
    mq.addListener(callback);
  }
}
addMQListener(window.matchMedia("(orientation:landscape)"),
  event => {
    if (event.matches) {
      /* now in landscape orientation */
    } else {
      /* now in portrait orientation */
    }
  }
);
					

规范

规范 状态 注释
CSSOM (CSS 对象模型) 视图模块
The definition of 'matches' in that specification.
工作草案 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
匹配 Chrome 9 Edge 12 Firefox 6 IE 10 Opera 12.1 Safari 5.1 WebView Android Yes Chrome Android 18 Firefox Android Yes Opera Android Yes Safari iOS 5 Samsung Internet Android 1.0

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: