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:回答3:<!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. 请问带渐变背景的进度条如何实现?求给点思路2. javascript - 读js权威指南“作为值得函数”产生了疑惑,求释疑3. python3.x - python中的虚拟环境怎样设置一直处于激活状态4. boostrap怎么在移动端不显示sidebar?5. 网页爬虫 - Python爬虫返回状态码与实际情况不符?6. arguments问题7. mysql - 数据库建字段,默认值空和empty string有什么区别 1108. python中merge后文件莫名变得非常大9. file - Python如何读文件内容修改后写回原文件10. javascript - 为什么 process.stdin 会有 write 方法◔ ‸◔?