Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
window.matchMediaの話
Search
kokushin
February 26, 2018
Programming
200
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
window.matchMediaの話
Nagoya js @20180225
kokushin
February 26, 2018
More Decks by kokushin
See All by kokushin
趣味全開のAITuber開発
kokushin
0
1.1k
AI彼女とペアプロする話
kokushin
2
620
AI彼女の感情制御を頑張る話
kokushin
3
940
サイト制作における、より効果的な演出テクニックとは?
kokushin
1
140
Other Decks in Programming
See All in Programming
Spec-driven Development with AI
simas
PRO
0
2.2k
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
15
8.4k
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
140
Performance Optimization With LLMs
xleitix
0
240
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
140
TS 7.0 で baseUrl が使えなくなった今、パスエイリアスをどうするか
bicstone
2
460
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
710
Inertia Rails: The One-Person Framework with React & Friends
skryukov
0
210
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
280
ChromeでローカルLLM
ryu1013
0
190
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
560
Next.js: The final boss of Web Performance
guaca
0
380
Featured
See All Featured
Docker and Python
trallard
47
4.2k
A Tale of Four Properties
chriscoyier
163
24k
Skip the Path - Find Your Career Trail
mkilby
1
280
Site-Speed That Sticks
csswizardry
13
1.6k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
A designer walks into a library…
pauljervisheath
211
25k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
240
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
390
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Transcript
window.matchMediaͷ ɹ@kokushing
window.matchMedia ͬͯ·͔͢ʁ
ͳʹͦΕ • CSSͷϝσΟΞΫΤϦʢͱಉ͡هड़ʣΛJSͰ͑Δ windowΦϒδΣΫτͷϝιου • Οϯυͷ෯ɾߴ͕͞ΫΤϦͷ݅จͱҰக͢Ε matchesϓϩύςΟ͕tureΛฦ͢ • addListenerϝιουΛݺͼग़͢͜ͱͰϦεφΛొ͠ɺɹ resizeΠϕϯτͷΑ͏ʹαΠζมߋΛݕ͢Δ͜ͱՄೳ
• IE10Ҏ্Ͱಈ͘
None
࣮ࡍͷσϞ https://kokushin.github.io/matchMedia/
// メディアクエリリストの作成 const mql = window.matchMedia('(max-width: 767px)'); // クエリの条件分に従って処理させる const
handleScaleChange = (mql) => { if (mql.matches) { /* ウィンドウの横幅が767px以下の場合 */ } else { /* ウィンドウの横幅が768px以上の場合 */ } } // メディアクエリリストをリスナに登録 mql.addListener(handleScaleChange); // 初回実⾏ handleScaleChange(mql);
ϝϦοτ • CSSͷϝσΟΞΫΤϦͱಉ͡هड़ͳͷͰ݅จ͕ཧղ͠ ͍͢ = ಋೖίετΊ • ݅จͱҰகͨ͠ͱ͖ʹҰ͚ͩॲཧ͞ΕΔͷͰonresize ΠϕϯτൃՐ࣌ͷແବͳϑϥάཧΛ͢Δඞཁͳ͍ let
changeFlag = false; if (!changeFlag) { /* ウィンドウサイズが変わったときの処理 */ changeFlag = true; }
ϝσΟΞΫΤϦͱಉ͡ͳͷͰ… • (min-width: 1000px) and (max-width: 1200px) ͳͲෳࡶͳ ݅จॻ͖͍͢ •
(orientation: portrait) (orientation: landscape) ͳͲ ͑ΔͷͰॎԣൺͷผʹ༗ޮ
YES! matchMedia
window.matchMedia - Web API ΠϯλʔϑΣΠε | MDN https://developer.mozilla.org/ja/docs/Web/API/Window/matchMedia
εΫϦϓτ͔ΒͷϝσΟΞΫΤϦͷ༻ | MDN https://developer.mozilla.org/ja/docs/Web/Guide/CSS/Testing_media_queries
એ https://www.makepost.net/