use window matchMedia.

This commit is contained in:
Miroslav Šedivý 2023-04-19 12:28:14 +02:00
parent f9417db520
commit 9b851aac61
3 changed files with 4 additions and 4 deletions

View File

@ -89,7 +89,7 @@
this.unsubscribePixelRatioChange() this.unsubscribePixelRatioChange()
} }
const media = matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`) const media = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`)
media.addEventListener('change', this.onPixelRatioChange) media.addEventListener('change', this.onPixelRatioChange)
this.unsubscribePixelRatioChange = () => { this.unsubscribePixelRatioChange = () => {
media.removeEventListener('change', this.onPixelRatioChange) media.removeEventListener('change', this.onPixelRatioChange)

View File

@ -249,9 +249,9 @@
// check if the device has a touch screen // check if the device has a touch screen
('ontouchstart' in window || navigator.maxTouchPoints > 0) && ('ontouchstart' in window || navigator.maxTouchPoints > 0) &&
// we also check if the device has a pointer // we also check if the device has a pointer
!matchMedia('(pointer:fine)').matches && !window.matchMedia('(pointer:fine)').matches &&
// and is capable of hover, then it probably has a mouse // and is capable of hover, then it probably has a mouse
!matchMedia('(hover:hover)').matches !window.matchMedia('(hover:hover)').matches
) )
} }

View File

@ -513,7 +513,7 @@
this.unsubscribePixelRatioChange() this.unsubscribePixelRatioChange()
} }
const media = matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`) const media = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`)
media.addEventListener('change', this.onPixelRatioChange) media.addEventListener('change', this.onPixelRatioChange)
this.unsubscribePixelRatioChange = () => { this.unsubscribePixelRatioChange = () => {
media.removeEventListener('change', this.onPixelRatioChange) media.removeEventListener('change', this.onPixelRatioChange)