media
只读特性在
MediaQueryList
接口是
DOMString
representing a serialized media query.
var media = MediaQueryList.media;
A
DOMString
representing a serialized media query.
This example runs the media query
(max-width: 600px)
and displays the value of the resulting
MediaQueryList
's
media
property in a
<span>
.
let mql = window.matchMedia('(max-width: 600px)');
document.querySelector(".mq-value").innerText = mql.media;
The JavaScript code simply passes the media query to match into
matchMedia()
to compile it, then sets the
<span>
's
innerText
to the value of the result's
media
特性。
<span class="mq-value"></span>
简单
<span>
to receive the output.
.mq-value {
font: 18px arial, sans-serif;
font-weight: bold;
color: #88f;
padding: 0.4em;
border: 1px solid #dde;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSSOM (CSS 对象模型) 视图模块
The definition of 'media' in that specification. |
工作草案 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
media
|
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