1<script>
2if (window.matchMedia("(min-width: 600px)").matches) {
3 /* La largeur minimum de l'affichage est 600 px inclus */
4} else {
5 /* L'affichage est inférieur à 600px de large */
6}
7</script>
1<!DOCTYPE html>
2<html>
3<head>
4<meta name="viewport" content="width=device-width, initial-scale=1">
5</head>
6<body>
7
8<p>If the viewport is less than, or equal to, 700 pixels wide, the background color will be yellow. If it is greater than 700, it will change to pink.</p>
9<p><strong>Resize the browser window to see the effect.</strong></p>
10
11<script>
12function myFunction(x) {
13 if (x.matches) { // If media query matches
14 document.body.style.backgroundColor = "yellow";
15 } else {
16 document.body.style.backgroundColor = "pink";
17 }
18}
19
20var x = window.matchMedia("(max-width: 700px)")
21myFunction(x) // Call listener function at run time
22x.addListener(myFunction) // Attach listener function on state changes
23</script>
24
25</body>
26</html>
27