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 - 粘贴一段带有图片和文字的内容,如何使用js实现获取图片并上传到服务器?2. css3 - css line-height和font-size高度问题,谁能帮忙解释一下呢3. javascript - 如何使用nodejs 将.html 文件转化成canvas4. java - 使用 RedisTemplate 操作数据5. mysql - SELECT 多個資料表及多個欄位6. css - Hexo next 主题 新增 自定义 Menus 字母怎么能首字母不自动大写?7. 收缩页面显示的图片怎么写8. python - django 项目的 migrations 目录是否应该提交到 git9. java - .jsp页面用<%= %>的方式获取数据存在一个很奇怪的问题10. 怎么学好php

网公网安备