javascript - 想通过js判断css的媒体查询 出错
问题描述
@media screen and (min-width: 360px) and (max-width: 375px){ .ejiao_description .form form p{margin-bottom: 11px; }}
css中媒体查询是这么写的js
var screen1 = window.matchMedia(’@media (min-width: 360px) and (max-width: 375px)’); if (screen1.matches){XXXXXX..... } else{XXXX.... }
但是现在没起作用 请问哪里错了么
问题解答
回答1:https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
请看文档
回答2:<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Title</title> <style>@media screen and (min-width: 360px) and (max-width: 375px){ .aa .form form p{margin-bottom: 11px; }} </style></head><body><!-- 想通过js判断css的媒体查询 出错 --><p class='aa'> <p class='form'><form> <p>123123</p></form> </p></p></body><script> var screen1 = window.matchMedia(’(min-width: 360px) and (max-width: 375px)’); console.log( screen1 ); if (screen1.matches){console.log( 1 ); } else{console.log( 2 ); }</script></html>
为window.matchMedia(’(min-width: 360px) and (max-width: 375px)’);,没@media
相关文章:
1. docker start -a dockername 老是卡住,什么情况?2. javascript - js 多维数组的问题3. debian - docker依赖的aufs-tools源码哪里可以找到啊?4. javascript eval5. 在windows下安装docker Toolbox 启动Docker Quickstart Terminal 失败!6. docker不显示端口映射呢?7. 在mac下出现了两个docker环境8. css - input间的间距和文字上下居中9. angular.js - angular指令中的scope属性中用&获取父作用域函数的问题10. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””
![javascript - js 多维数组的问题](http://www.haobala.com/attached/image/14.jpg)