aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/window/matchmedia/index.html
blob: 224edecbd18b3d331901851636797f5dfc04d831 (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
---
title: Window.matchMedia()
slug: Web/API/Window/matchMedia
tags:
  - API
  - CSSOM View
  - JavaScript
  - Media Queries
  - Method
  - Reference
translation_of: Web/API/Window/matchMedia
---
<div>{{APIRef}}</div>

<p><strong><code>Window.matchMedia()</code></strong> 메서드는 주어진 <a href="/ko/docs/Web/Guide/CSS/Media_queries">미디어 쿼리</a> 문자열의 분석 결과를 나타내는 {{domxref("MediaQueryList")}} 객체를 반환합니다.</p>

<h2 id="Syntax" name="Syntax">구문</h2>

<pre class="syntaxbox">window.matchMedia(<em>mediaQueryString</em>)</pre>

<h3 id="매개변수">매개변수</h3>

<dl>
 <dt><code>mediaQueryString</code></dt>
 <dd>분석할 미디어 쿼리를 나타내는 문자열.</dd>
</dl>

<h3 id="반환_값">반환 값</h3>

<p>주어진 미디어 쿼리에 대한 {{domxref("MediaQueryList")}} 객체,</p>

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

<p>다음 예제는 화면이 매우 좁을 때 다른 작업을 수행합니다.</p>

<pre class="brush: js">if (window.matchMedia("(min-width: 400px)").matches) {
  /* 뷰포트 너비가 400 픽셀 이상 */
} else {
  /* 뷰포트 너비가 400 픽셀 미만 */
}
</pre>

<p>더 많은 예제는 <a href="/ko/docs/Web/CSS/Media_Queries/Testing_media_queries">Testing media queries programmatically</a>를 참고하세요.</p>

<h2 id="명세">명세</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("CSSOM View", "#dom-window-matchmedia", "Window.matchMedia()")}}</td>
   <td>{{Spec2("CSSOM View")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">브라우저 호환성</h2>



<p>{{Compat("api.Window.matchMedia")}}</p>

<h2 id="See_also" name="See_also">같이 보기</h2>

<ul>
 <li><a href="/ko/docs/Web/Guide/CSS/Media_queries">미디어 쿼리 사용하기</a></li>
 <li><a href="/en-US/docs/DOM/Using_media_queries_from_code" title="CSS/Using media queries from code">Using media queries from code</a></li>
 <li>{{domxref("MediaQueryList")}}</li>
 <li>{{domxref("MediaQueryListListener")}}</li>
</ul>