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. mysql - JAVA怎么实现一个DAO同时实现查询两个实体类的结果集2. sql语句 - 如何在mysql中批量添加用户?3. mysql建表报错,查手册看不懂,求解?4. PHP类属性声明?5. 求大神支招,php怎么操作在一个html文件的<head>标记内添加内容?6. 怎么php怎么通过数组显示sql查询结果呢,查询结果有多条,如图。7. 致命错误: Class ’appfacadeTest’ not found8. 老师们php,插入数据库mysql,都是空的,要怎么解决9. mysql - 数据库建字段,默认值空和empty string有什么区别 11010. phpstady在win10上运行
