Quantcast
Channel: CSSタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8833

レスポンシブサイトでデバイスサイズごとにJSを切り替える。

$
0
0

PCとSPでデザインが違う時に、使用したので忘れずにメモ。

script.js
jQuery(document).ready(function($){if(window.matchMedia('(min-width: 768px)').matches){$(function(){/* ウィンドウサイズが768px以上の場合 */});}else{$(function(){/* ウィンドウサイズが768px未満の場合 */});};});

タブレットの時とかにも使える◎

script.js
if(window.matchMedia("(max-width: 768px) and (min-width: 480px)").matches){/* ウィンドウサイズが 480px以上768px以下の場合 */}

Viewing all articles
Browse latest Browse all 8833

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>