• Stars
    star
    429
  • Rank 101,271 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple, tiny alternative to element/container queries

eqio logo

eqio

A simple, tiny alternative to element/container queries

eqio allows you to attain the holy grail of responsive web development/design systems: components that can adapt their styling based on their width, not the browser‘s.

It uses IntersectionObservers under-the-hood (so is well supported in “good” browsers and easily polyfilled in others) to apply appropriately named classes to the component when necessary.

Table of Contents

Demo

A complete demo is available here: https://codepen.io/stowball/pen/zPYzWd

Installation

npm

npm install eqio --save

Direct <script> include

<script src="https://unpkg.com/eqio/umd/eqio.min.js"></script>

Usage

The HTML

  1. Add a class of eqio to the element.
  2. Add a data-eqio-sizes attribute whose value is a JSON-serializable array of sizes.
  3. Optionally add a data-eqio-prefix attribute whose value is used as the prefix for your class names.
<div
  class="media-object eqio"
  data-eqio-sizes='["<400", ">700"]'
  data-eqio-prefix="media-object"
></div>

The above component will:

  • be able to be customised when its width is 400 or smaller ("<" is a synonym for max-width, not “less than”).
  • be able to be customised when its width is 700 or greater (">" is a synonym for min-width, not “greater than”).
  • apply the following classes media-object-eqio-<400 and media-object-eqio->700 as appropriate. If data-eqio-prefix had not been specified, the applied classes would be eqio-<400 and eqio->700.

Note: Multiple classes can be applied at once.

The CSS

In your CSS, write class names that match those applied to the HTML.

.media-object-eqio-\<400 {
  /* customizations when less than or equal to 400px */
}

.media-object-eqio-\>700 {
  /* customizations when greater than or equal to 700px */
}

Note:

  • eqio classes include the special characters < & >, so they must be escaped with a \ in your CSS.
  • eqio elements are position: relative by default, but your component can override that to absolute/fixed etc as required.
  • eqio elements can't be anything but overflow: visible.
  • To prevent accidental creation of horizontal scrollbars, a parent element is required to overflow-x: hidden. It is recommended to apply this to body.

The JavaScript

If using a module bundler, such as webpack, first import Eqio.

import Eqio from 'eqio';

In your JS, tell eqio which elements are to be made responsive by passing a DOM reference to Eqio.

var mediaObject = new Eqio(document.querySelector('.media-object'));

Should you need to stop this element from being responsive, you can call .stop() on your instance:

mediaObject.stop();

This will remove all observers and eqio internals, except for the class names that were applied at the time.


Copyright (c) 2018 Matt Stow
Licensed under the MIT license (see LICENSE for details)

More Repositories

1

jQuery-rwdImageMaps

Responsive Image Maps jQuery Plugin
JavaScript
1,556
star
2

dummys-guide-to-redux-and-thunk-react

Tutorial post
JavaScript
321
star
3

react-native-svg-icon

A simple, but flexible SVG icon component for React Native
JavaScript
177
star
4

rwd.images.js

Yet another lightweight, customisable responsive image solution
JavaScript
115
star
5

RWD-Retrofit

Allows an existing desktop site to co-exist with a responsive site, while also able to serve the desktop site to a different breakpoint on "mobile"
JavaScript
104
star
6

Suzi

A mature, feature-rich, responsive Sass and Grunt UI framework
CSS
102
star
7

Layout-Engine

Adds the rendering engine name as a class on the html tag and returns a JavaScript object containing the vendor, version and browser name (where appropriate)
JavaScript
96
star
8

mqGenie

Adjusts CSS media queries in browsers that include the scrollbar width in the viewport width so they fire at the intended size
JavaScript
89
star
9

hucssley

Hucssley - a full-featured, consistent, atomic utility class library for rapidly building performant UI
SCSS
78
star
10

quench-vue

Simple, client-side hydration of pre-rendered Vue.js apps
JavaScript
75
star
11

elf

Elf is a simple & magical Eleventy starter kit to help you create a project using standard technologies like webpack, Babel and Sass, while also considering ease of use, performance and browser compatibility.
JavaScript
51
star
12

jQuery-rwdImages

Allows responsive content images using the redux spacer technique (http://mattstow.com/experiment/responsive-images-redux/responsive-images-redux-jquery-plugin.html) to be shared and saved
JavaScript
43
star
13

Viewport-Genie

Adds the real viewport width and height (in px and em) as an element on the body to help with obtaining values for responsive breakpoints
JavaScript
37
star
14

Class-Query

A simple method to help manage responsive content (and an alternative to element queries as an added bonus)
JavaScript
31
star
15

keyboard-focus

A rudimentary way to detect users that navigate with the Tab key
JavaScript
25
star
16

react-accessible-tabs

An accessible React tabs component
JavaScript
24
star
17

Adobe-Blank

Reduced/subset version to "English"-only characters
CSS
12
star
18

webpack-svg-icon-system

A loader and plugin for webpack that converts all your SVGs into symbols and merges them into a SVG sprite.
JavaScript
10
star
19

ikuno

A simple, Grunt image and SVG optimiser
JavaScript
10
star
20

react-native-bem

A tiny, fast, BEM-inspired method to styling React Native components
JavaScript
9
star
21

swinch.js

A lightweight, customisable, horizontal touch detection script
JavaScript
4
star
22

hucssley-hireup-demo

JavaScript
1
star
23

Suzi-Code-Hints

Adds code hint support for all of Suzi's mixins and functions: https://github.com/izilla/Suzi#mixins-and-functions
1
star
24

littlelink-blossoming

CSS
1
star
25

hireup-assets

1
star
26

github-pr-approvals

A Greasemonkey script to require approvals in GitHub PRs before merging is allowed
JavaScript
1
star
27

brackets-legibility

Increase the legibility of Brackets' UI. Useful for High DPI screens
CSS
1
star
28

hucssley-hireup-demo-vue

Vue
1
star
29

Not-Required

Removes all required field attributes to test form submissions
JavaScript
1
star
30

color-flashcards

A simple web app (in under 10kb gzipped) to help teach your children colors with both visual and audio cues.
JavaScript
1
star
31

simple-social-media

A simple, mock-social media, client-side Angular application
JavaScript
1
star
32

suzi.grid.js

A JavaScript implementation of Suzi's grid system for rapid development
JavaScript
1
star