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
Transcript
12 slides
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/
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
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
350
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
130
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
240
LLM 101
dalinaum
0
490
Будущее локальных LLM – Алексей Голобурдин, PythoNN
sobolevn
0
120
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.4k
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
300
複数ドメインを一つのアプリに統合するFlutterの設計と運用_FlutterKaigi2026登壇資料(須永高弘)
takahirosunaga
0
190
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
0
220
SODA - FACT BOOK(EN)
sodainc
1
240
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
240
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
680
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Code Reviewing Like a Champion
maltzj
529
40k
How to train your dragon (web standard)
notwaldorf
96
6.9k
How to make the Groovebox
asonas
2
2.6k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
980
Making Projects Easy
brettharned
120
6.9k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
620
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
480
Typedesign – Prime Four
hannesfritz
42
3.2k
We Have a Design System, Now What?
morganepeng
55
8.4k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
330
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
350