aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/mediaquerylist/matches/index.html
blob: cfac80270d6d27ddddb8dee1e591537535c4cbe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
title: MediaQueryList.matches
slug: Web/API/MediaQueryList/matches
tags:
  - API
  - Adaptive Design
  - CSSOM
  - CSSOM View
  - DOM
  - Media Queries
  - MediaQueryList
  - Property
  - Reference
  - matches
  - アダプティブデザイン
  - プロパティ
  - メディアクエリ
translation_of: Web/API/MediaQueryList/matches
---
<p>{{APIRef("CSSOM")}}</p>

<p><strong><code>matches</code></strong>{{DOMxRef("MediaQueryList")}} インターフェイスの読み取り専用プロパティで、 {{jsxref("Boolean")}} であり、文書が現在メディアクエリリストと一致している場合は <code>true</code> を返し、一致していない場合は <code>false</code> を返します。</p>

<p><code>matches</code> の値が変化した場合は、 <code>MediaQueryList</code> で発生する {{domxref("MediaQueryList.change_event", "change")}} イベントを監視することで通知を受けることができます。</p>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre class="syntaxbox notranslate">var <var>matches</var> = &lt;varm&gt;MediaQueryList.matches;</pre>

<h3 id="Value" name="Value"></h3>

<p>{{DOMxRef("Boolean")}}{{DOMxRef("document")}} が現在メディアクエリーのリストに一致していれば <code>true</code> を返し、そうでなければ <code>false</code> を返します。</p>

<h2 id="Example" name="Example"></h2>

<p>この例では <code><a href="/ja/docs/Web/CSS/@media/orientation">orientation</a></code> メディア特性を使用したメディアクエリを作成することにより、ビューポートの向きの変化を検出します。</p>

<pre class="brush: js notranslate">function addMQListener(mq, callback) {
  if (mq.addEventListener) {
    mq.addEventListener("change", callback);
  } else {
    mq.addListener(callback);
  }
}

addMQListener(window.matchMedia("(orientation:landscape)"),
  event =&gt; {
    if (event.matches) {
      /* 横向きの画面になった */
    } else {
      /* 縦向きの画面になった */
    }
  }
);
</pre>

<h2 id="Specifications" name="Specifications">仕様書</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">仕様書</th>
   <th scope="col">状態</th>
   <th scope="col">備考</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("CSSOM View", "#dom-mediaquerylist-matches", "matches")}}</td>
   <td>{{Spec2("CSSOM View")}}</td>
   <td>編集者草稿</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>

<p>{{Compat("api.MediaQueryList.matches")}}</p>

<h2 id="See_also" name="See_also">関連情報</h2>

<ul>
 <li><a href="/ja/docs/CSS/Media_queries">メディアクエリ</a></li>
 <li><a href="/ja/docs/CSS/Using_media_queries_from_code">コードからのメディアクエリの使用</a></li>
 <li>{{DOMxRef("window.matchMedia()")}}</li>
 <li>{{DOMxRef("MediaQueryList")}}</li>
 <li>{{DOMxRef("MediaQueryListEvent")}}</li>
</ul>