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.... }
但是現(xiàn)在沒起作用 請問哪里錯了么
問題解答
回答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
相關(guān)文章:
1. bootstrp是col-md-12列的,只有col-md-10有內(nèi)容,可以讓沒有內(nèi)容的不占據(jù)位置嗎;2. 常量在外面不加引號會報錯。3. wordpress里,這樣的目錄列表是屬于小工具還是啥?4. android - Genymotion 微信閃退 not find plugin.location_google.GoogleProxyUI5. python如何設(shè)置一個隨著系統(tǒng)時間變化的動態(tài)變量?6. 百度地圖 - Android app中準備接入地圖sdk,百度VS高德哪個好一點?7. 我的怎么不顯示啊,話說有沒有QQ群什么的8. mysql federated引擎無法開啟9. MySQL 使用 group by 之后然后 IFNULL(COUNT(*),0) 為什么還是會獲得 null10. sublime text3安裝package control失敗
