blob: a6497ded0a7b7a18e5d731315c873fcfaeb2cf55 (
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
---
title: Window.matchMedia()
slug: Web/API/Window/matchMedia
translation_of: Web/API/Window/matchMedia
---
<div>{{APIRef}}</div>
<h2 id="Summary" name="Summary">Resumo</h2>
<p>Retorna um novo objeto {{domxref("MediaQueryList")}} representando o resultado analisado da string <a href="/en-US/docs/CSS/Media_queries" title="CSS/Media queries">media query</a> especificada.</p>
<h2 id="Syntax" name="Syntax">Sintaxe</h2>
<pre class="syntaxbox"><em>mql</em> = window.matchMedia(<em>mediaQueryString</em>)</pre>
<p>onde <code>mediaQueryString</code> é uma string representando a media query para o qual retorna um novo objeto {{domxref("MediaQueryList")}}.</p>
<h2 id="Example" name="Example">Exemplo</h2>
<pre class="brush: js">if (window.matchMedia("(min-width: 400px)").matches) {
/* a viewport tem pelo menos 400 pixels de largura */
} else {
/* a viewport menos que 400 pixels de largura */
}</pre>
<p>Este código permite-lhe lidar com as coisas de forma diferente quando a janela é muito estreita.</p>
<p>Veja <a href="/en-US/docs/DOM/Using_media_queries_from_code" title="CSS/Using media queries from code">Usando media queries a partir do código</a> para mais exemplos.</p>
<h2 id="Specifications" name="Specifications">Especificações</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Especificações</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">Compatibilidade do navegador</h2>
<p>{{CompatibilityTable()}}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td>9</td>
<td>{{CompatGeckoDesktop("6.0")}}</td>
<td>10</td>
<td>12.1</td>
<td>5.1</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>3.0</td>
<td>{{CompatGeckoMobile("6.0")}}</td>
<td>{{CompatNo}}</td>
<td>12.1</td>
<td>5</td>
</tr>
</tbody>
</table>
</div>
<h2 id="See_also" name="See_also">Veja também</h2>
<ul>
<li><a href="/en-US/docs/CSS/Media_queries" title="CSS/Media queries">Media queries</a></li>
<li><a href="/en-US/docs/DOM/Using_media_queries_from_code" title="CSS/Using media queries from code">Usando media queries a partir do código</a></li>
<li>{{domxref("MediaQueryList")}}</li>
<li>{{domxref("MediaQueryListListener")}}</li>
</ul>
|