aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/mediaquerylist/onchange/index.html
blob: 5539cdd3c76fa7ef7e71751eaf4ce6e46df1b355 (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
---
title: MediaQueryList.onchange
slug: Web/API/MediaQueryList/onchange
tags:
  - API
  - CSSOM View
  - Event Handler
  - MediaQueryList
  - Property
  - Reference
  - onchange
  - イベントハンドラー
  - プロパティ
  - メディアクエリ
translation_of: Web/API/MediaQueryList/onchange
---
<p>{{APIRef("CSSOM")}}</p>

<p><code><strong>onchange</strong></code>{{DOMxRef("MediaQueryList")}} インターフェイスのプロパティで、 {{domxref("MediaQueryList/change_event", "change")}} イベントが発行されたとき、すなわちメディアクエリの対応の状態が変化したときに呼び出される関数を表します。イベントオブジェクトは {{DOMxRef("MediaQueryListEvent")}} のインスタンスであり、古いブラウザーからは後方互換性のために <code>MediaListQuery</code> のインスタンスと解釈されます。</p>

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

<pre class="syntaxbox notranslate"><var>MediaQueryList</var>.onchange = function() { ... };</pre>

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

<pre class="brush: js notranslate">var mql = window.matchMedia('(max-width: 600px)');

mql.addEventListener( "change", (e) =&gt; {
    if (e.matches) {
    /* ビューポートが 600 ピクセル幅以下 */
    console.log('This is a narrow screen — less than 600px wide.')
  } else {
    /* ビューポートが 600 ピクセル幅より広い */
    console.log('This is a wide screen — more than 600px wide.')
  }
})

</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-onchange", "onchange")}}</td>
   <td>{{Spec2("CSSOM View")}}</td>
   <td>初回定義</td>
  </tr>
 </tbody>
</table>

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

<p>{{Compat("api.MediaQueryList.onchange")}}</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>