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. javascript - npm下载的模块不完整是什么问题?2. java - Spring事务回滚问题3. python运行后没有任何反馈要怎么排查4. html5 - iphone5手机,微信中无法打开优酷链接?5. node.js - 我想让最后进入数据库的数据,在前台最先展示,如何做到?6. wordpress - Nginx中禁止访问txt,robots.txt文件例外,规则该怎么写?7. 刚放到服务器的项目出现这中错误,有高手指点吗8. css - 手机qq打开网页无法使用文件上传功能?9. python 操作mysql如何经量防止自己的程序在之后被恶意注入(说白了就是问一下python防注入的一些要点)10. mysql - 面试题:如何把login_log表转换成last_login表?
