-
Notifications
You must be signed in to change notification settings - Fork 0
isBreakpoint
Mike Byrne edited this page Aug 24, 2022
·
7 revisions
Checks if the current breakpoint matches the passed breakpoint. It supports querying with or without +/- modifiers.
Uses getCurrentMediaQuery
to read a CSS variable describing the name of the current breakpoint, see getCurrentMediaQuery
doc.
- breakpoint - required - the breakpoint to match current breakpoint against
- breakpoints - optional - array of breakpoint names to test against
- boolean
// returns true (if viewport is 'md' size)
var isMediumViewport = isBreakpoint('md');
// returns true (if viewport is 'lg', 'lg' or 'xxlarge' lg)
var isLargerViewport = isBreakpoint('lg+');
// returns true (if viewport is 'sm' or 'xs' size)
var isSmallerViewport = isBreakpoint('sm-');
The default list of breakpoints is: ['xs', 'sm', 'md', 'lg', 'xl', 'xxl']
You can override this by including your application breakpoints, smallest to largest, as an array as the optional second parameter:
// returns true (if viewport is 'medium' size)
var applicationBreakpoints = ['small', 'medium', 'large', 'xlarge'];
var isMediumViewport = isBreakpoint('medium', applicationBreakpoints);
Or, you can set this globally using:
// app.js
// override default breakpoints (optional)
var A17 = window.A17 || {};
A17.breakpoints = [ 'small', 'medium', 'large' ];
var isMediumViewport = isBreakpoint('medium');