MediaQueryList

Обновлено: 23.03.2023

Об’єкт MediaQueryList

Об’єкт MediaQueryList зберігає інформацію з медіа-запиту.

Об'єкт MediaQueryList є властивістю об'єкта window .

Доступ до об’єкта MediaQueryList здійснюється за допомогою:

window.matchMedia()або просто matchMedia().

Властивості MediaQueryList

PropertyDescription
matchesA boolean.
true if the document matches the query, otherwise false.
mediaA string.
A media query (list).

Методи MediaQueryList

MethodDescription
addListener()Adds a new listener function, which is executed whenever the media query's evaluated result changes
removeListener()Removes a previously added listener function from the media query list. Does nothing if the specified listener is not already in the list

Медіа запити

Медіа-запити методу matchMedia()можуть бути будь-якими медіа-функціями правила CSS @media , наприклад min-height, min-width, orientation тощо.

Типи носіїв

ValueDescription
allDefault. Used for all media type devices
printUsed for printers
screenUsed for computer screens, tablets, smart-phones etc.
speechUsed for screenreaders that "reads" the page out loud

Функції медіа

ValueDescription
any-hoverDoes any available input mechanism allow the user to hover over elements? (added in Media Queries Level 4)
any-pointerIs any available input mechanism a pointing device, and if so, how accurate is it? (added in Media Queries Level 4)
aspect-ratioThe ratio between the width and the height of the viewport
colorThe number of bits per color component for the output device
color-gamutThe approximate range of colors that are supported by the user agent and output device (added in Media Queries Level 4)
color-indexThe number of colors the device can display
gridWhether the device is a grid or bitmap
heightThe viewport height
hoverDoes the primary input mechanism allow the user to hover over elements? (added in Media Queries Level 4)
inverted-colorsIs the browser or underlying OS inverting colors? (added in Media Queries Level 4)
light-levelCurrent ambient light level (added in Media Queries Level 4)
max-aspect-ratioThe maximum ratio between the width and the height of the display area
max-colorThe maximum number of bits per color component for the output device
max-color-indexThe maximum number of colors the device can display
max-heightThe maximum height of the display area, such as a browser window
max-monochromeThe maximum number of bits per "color" on a monochrome (greyscale) device
max-resolutionThe maximum resolution of the device, using dpi or dpcm
max-widthThe maximum width of the display area, such as a browser window
min-aspect-ratioThe minimum ratio between the width and the height of the display area
min-colorThe minimum number of bits per color component for the output device
min-color-indexThe minimum number of colors the device can display
min-heightThe minimum height of the display area, such as a browser window
min-monochromeThe minimum number of bits per "color" on a monochrome (greyscale) device
min-resolutionThe minimum resolution of the device, using dpi or dpcm
min-widthThe minimum width of the display area, such as a browser window
monochromeThe number of bits per "color" on a monochrome (greyscale) device
orientationThe orientation of the viewport (landscape or portrait mode)
overflow-blockHow does the output device handle content that overflows the viewport along the block axis (added in Media Queries Level 4)
overflow-inlineCan content that overflows the viewport along the inline axis be scrolled (added in Media Queries Level 4)
pointerIs the primary input mechanism a pointing device, and if so, how accurate is it? (added in Media Queries Level 4)
resolutionThe resolution of the output device, using dpi or dpcm
scanThe scanning process of the output device
scriptingIs scripting (e.g. JavaScript) available? (added in Media Queries Level 4)
updateHow quickly can the output device modify the appearance of the content (added in Media Queries Level 4)
widthThe viewport width