匹配
只读特性在
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. |
工作草案 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
匹配
|
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 |
完整支持
MediaQueryList
AnimationEvent
CSS
CSSConditionRule
CSSGroupingRule
CSSKeyframeRule
CSSKeyframesRule
CSSMediaRule
CSSNamespaceRule
CSSPageRule
CSSRule
CSSRuleList
CSSStyleDeclaration
CSSStyleRule
CSSStyleSheet
CSSSupportsRule
CaretPosition
LinkStyle
MediaQueryListListener
Screen
StyleSheet
StyleSheetList
TransitionEvent